How to query a MySQL Database in PHP

<h1>MySQL Test Code Results</h1> 
 
</> 
<table border="1"
<tr> 
  <td> 
  pkID 
  </td> 
    <td> 
    username 
    </td> 
      <td> 
      password 
      </td> 
</tr> 
 
<?php 
// Configuration Information and Definitions 
 
$mysql_host = 'mysql01.discountasp.net'
$mysql_user = 'username'
$mysql_pass = 'password'
$mysql_db = 'database'
$query = 'SELECT * from table1'
 
mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Connection to MySQL-server failed!"); 
 
mysql_select_db($mysql_db) or die("Selection of database $mysql_db failed!"); 
 
$result = mysql_query($query) or die("Invalid Query, " . mysql_error()); 
 
while( list( $pkid, $user, $pass ) = mysql_fetch_row($result) ) { 
 printf("<tr><td>%d</td><td>%s</td><td>%s</td></tr>", $pkid, $user, $pass); 
?> 
 
</table> 
 
</> 
 
<b>End MySQL Test Code Results</b> 

If you run into problems when using this code, please post in our community forum. Technical support is unable to assist with specific coding issues.

Article ID: 360, Created On: 11/24/2008, Modified: 11/22/2010