Skip to content

Instantly share code, notes, and snippets.

@anvyst
Created April 26, 2011 10:22
Show Gist options
  • Save anvyst/942080 to your computer and use it in GitHub Desktop.
Save anvyst/942080 to your computer and use it in GitHub Desktop.
MySQL sample database
<?php
$connectionHandler = mysql_connect("localhost","username","password");
if( !$connectionHandler ) {
die("Connection Failed: " . mysql_error());
}
$dbname = 'users_db';
mysql_select_db($dbname);
//some simple select queries to test connection
$sql = "SELECT * from users ORDER BY id ASC";
$result = mysql_query($sql);
//couldn't run the qry
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
//empty resultSet
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row["id"];
echo $row["name"];
}
//closing mysql-connection
mysql_close($connectionHandler);
?>
/* creating schema users_db*/
CREATE SCHEMA users_db;
USE SCHEMA users_db;
/* adding sample table */
CREATE TABLE users(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(200) default null
)ENGINE=MyISAM CHARSET=utf8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment