Bryan,

Here is a PHP function that I wrote that handles everything,
(1)..database open/connect
(2)..database query
(3)..database close
=============================================================

function thesqlquery($sqlquery)
{
include "./files-includes/config.inc.php";
//echo "<br/> Trying to connect to MySQL";
//echo '<br/> Hostname:(' . $host . ') UserID: (' . $user . ') Password:(' .
$passwd . ')';
if ( !$dbh = mysql_connect($host, $user, $passwd) )
 {
 $errmsg = mysql_errno($dbh) . ": " . mysql_error($dbh);
 echo "<br/>" . $errmsg;
 exit();
 }
//echo '<br/> DatabaseName:(' . $dbname . ')';
$db_selected = mysql_select_db($dbname, $dbh);
if (!$db_selected) {
 $errmsg = mysql_errno($dbh) . ": " . mysql_error($dbh);
 echo "<br/>" . $errmsg;
 exit();
}
//echo "<br/>SQLQUERY: " . $sqlquery;
if ( !$sqlresult = mysql_query($sqlquery, $dbh) )
 {
 echo "<br/>SQLQUERY: " . $sqlquery;
 $errmsg = mysql_errno($dbh) . ": " . mysql_error($dbh);
 echo "<br/>" . $errmsg;
 exit();
 }
 $numrows = mysql_num_rows($sqlresult);
 //echo "<br/>NumberOfRows: " . $numrows;
 mysql_close($dbh);
return $sqlresult;
}

=============================================================


--------------------------------------------------------------------------------------------------------------------------
The above mentioned config.inc.php file contains the following global
variables.
--------------------------------------------------------------------------------------------------------------------------
<?php
$host="localhost";
$user="your mysql userid/username";
$passwd="yourmysql password";
$dbname="yourmysql database name";
?>

--------------------------------------------------------------------------------------------------------------------------

Chuck


[Non-text portions of this message have been removed]

Reply via email to