PHP connect to a database and query a table:
<? # Connect mysql_connect('localhost', 'user', 'password') or die('Could not connect: ' . mysql_error()); # Choose a database mysql_select_db('dbname') or die('Could not select database'); # Perform database query $query = "SELECT * from table"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); # Filter through rows and echo desired information while ($row = mysql_fetch_object($result)) { echo $row->colname; } ?>
Tags:
PHP