Created
April 26, 2011 10:22
-
-
Save anvyst/942080 to your computer and use it in GitHub Desktop.
MySQL sample database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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