Changes

Jump to: navigation, search

Using PHP with MySQL

1,064 bytes added, 15:06, 7 June 2007
Selecting Records from a MySQL Database Using PHP
<pre>
<?php
 
$dbhandle = mysql_connect('localhost', 'phptest', '3579php');
 
if ($dbhandle == false)
{
die ("Unable to connect to MySQL Database<br>");
}
 
$db = mysql_select_db('PHPsampleDB');
 
if ($db == false)
{
die ("Unable to Select MySQL Database<br>");
}
 
$dbquery = 'SELECT * FROM customer';
 
$dbresult = mysql_query ($dbquery, $dbhandle);
 
if ($dbresult == false)
{
die ("Unable to to perform query<br>");
}
 
while ($dbrow = mysql_fetch_Array($dbresult, MYSQL_ASSOC))
{
print_r($dbrow);
echo '<br>';
}
?>
</pre>
 
When loaded into a browser the following output will be generated:
 
<tt>
Array ( [name] => Gregory House [email] => [email protected] [account] => 12345678 )<br>
Array ( [name] => Robert Chase [email] => [email protected] [account] => 87654321 )<br>
Array ( [name] => Lisa Cuddy [email] => [email protected] [account] => 24688642 ) <br>
</tt>

Navigation menu