<?php
//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
if (!mysql_select_db("my_database", $link)) {
echo " ERROR NO: " . mysql_errno($link) . "\n";
}
// Simple Select query
$query = "SELECT * FROM my_table";
// Execute the query
$mysql_result = mysql_query($query,$link)
or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');
// Grab the data from the result handle
$row = mysql_fetch_row($mysql_result);
// Grab the length of the data in the field
$length = mysql_fetch_lengths ($mysql_result);
echo"<table >
<tr <td>Field Name</td><td>Field Value</td><td>Data Length</td></tr>";
for ( $i = 0; $i < 3; $i++ ) {
// Grab the field name from from the result handle
$name = mysql_field_name( $mysql_result, $i );
//Display field name, field value and Data length
echo"<tr><td>$name</td><td>$row[$i]</td><td>$length[$i]</td></tr>";
}
echo"</table>";
mysql_close($link);
?>