Jump to Navigation

010 - To Connect MySQL

This is a sample to connect MySQL DB.

Example:

mysql_connect("localhost", "username", "password");

mysql_select_db("mydb");

$result = mysql_query("SELECT * FROM user_table");

if ($result && mysql_num_rows($result)) {

$numrows = mysql_num_rows($result);

$rowcount = 1;

print "There are $numrows people in user_table:<br /><br />";

while ($row = mysql_fetch_assoc($resiult)) {

print "Row $rowcount<br />";

foreach($row as $var => $val) {

print "<B>$var</B>: $val<br />";

}

print "<br />";

++$rowcount;

}

}



Main menu 2

Story | by Dr. Radut