body tag) function docheader() { // If content header has not been sent, // send it if (!headers_sent()) { header('Content-type: text/html'); } print << MySQL Query Result HTML; } // End docheader() // Connect the DB with the given creds function connectDB($server,$user,$password,$dbname) { $link = mysql_connect($server, $user, $password) or die("Could not connect to server!"); mysql_select_db($dbname) or die("Could not select database!"); return $link; } // End connectDB() // Do the query, return the result function doquery($link,$query) { $result = mysql_query($query,$link) or die("Could not perform query!") return $result; } // End doquery() // Output the results of the query in a table function dotable($result) { print << HTML; $line = mysql_fetch_array($result, MYSQL_ASSOC); $headers = array_keys($line); for ($i=0; $i <= count($headers) - 1; $i++) { print " ".$headers[$i]."\n"; } print "\n"; mysql_data_seek($result,0); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { print "\n"; foreach ($line as $key => $value) { print " ".$value."\n"; } print "\n"; } print "\n"; } // End dotable() // Document footer (close tags and end document) function docfooter() { print << HTML; } // End docfooter() // Main function function main() { // Connect the DB $link = connectDB("localhost","webuser","password99","mysqlsamp"); // Set up and perform query $query = <<