34,333
edits
Changes
→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>