Apr 9 2010

Quick PHP MySQL Connection Demo

Quick reference on how to connect to a MySQL database from PHP. There are other possibilities but this is a quick demo.

$db_host="localhost";
$db_user="test";
$db_password="test";
$db_name="test";

mysql_connect($db_host,$db_user, $db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result=mysql_query("select test from test_table");
while($row=mysql_fetch_array($result))
{
    echo $row['test'] , '
'; }