Traditional writing:
<?php
Echo"This is a test</br>";
Echo"ASDFASDFADSF";
$mysql _server_name="localhost";//Database server name
$mysql _username="Root";//Connect to database user name
$mysql _password="??????";//Connect Database Password
$mysql _database="??????";//the name of the database
//connecting to a database
$conn =mysql_connect ($mysql _server_name, $mysql _username,
$mysql _password);
//SQL statement that extracts information from a table
$strsql ="SELECT * from ' db_table '";
//Execute SQL query
$result =mysql_db_query ($mysql _database, $strsql, $conn);
//Get query Results
$row =mysql_fetch_row ($result);
Echo'<font face= "Verdana" >';
Echo'<table border= "1" cellpadding= "1" cellspacing= "2" >';
//Show Field names
Echo"</b><tr></b>";
for($i =0; $i <mysql_num_fields ($result); $i + +)
{
Echo'<td bgcolor= "#000F00" ><b>'.
Mysql_field_name ($result, $i);
Echo"</b></td></b>";
}
Echo"</tr></b>";
//Navigate to the first record
Mysql_data_seek ($result,0);
//Loop Out Records
while($row =mysql_fetch_row ($result))
{
Echo"<tr></b>";
for($i =0; $i <mysql_num_fields ($result); $i + +)
{
Echo'<td bgcolor= "#00FF00" >';
echo $row [$i];
Echo'</td>';
}
Echo"</tr></b>";
}
Echo"</table></b>";
Echo"</font>";
//Freeing Resources
Mysql_free_result ($result);
//Close Connection
Mysql_close ($conn);
?>
Shorthand:
<?php
$conn =mysql_connect ("localhost","Root","Password");
$result =mysql_db_query ("Database","SELECT * from ' db_table '", $conn);
//Get query Results
$row =mysql_fetch_row ($result);
Echo'<font face= "Verdana" >';
Echo'<table border= "1" cellpadding= "1" cellspacing= "2" >';
//Show Field names
Echo"</b><tr></b>";
for($i =0; $i <mysql_num_fields ($result); $i + +)
{
Echo'<td bgcolor= "#000F00" ><b>'.
Mysql_field_name ($result, $i);
Echo"</b></td></b>";
}
Echo"</tr></b>";
//Navigate to the first record
Mysql_data_seek ($result,0);
//Loop Out Records
while($row =mysql_fetch_row ($result))
{
Echo"<tr></b>";
for($i =0; $i <mysql_num_fields ($result); $i + +)
{
Echo'<td bgcolor= "#00FF00" >';
echo $row [$i];
Echo'</td>';
}
Echo"</tr></b>";
}
Echo"</table></b>";
Echo"</font>";
//Freeing Resources
Mysql_free_result ($result);
//Close Connection
Mysql_close ($conn);
?>
Echo came out of the main table
Reproduced in http://www.cnblogs.com/JamyWong/archive/2009/06/03/1495499.html
PHP connection MySQL