Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > PHP error for "if (mysql_connect_errno())"
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 3rd November 18:15
External User
 
Posts: 1
Default PHP error for "if (mysql_connect_errno())"



Can someone help me with an issue I'm having with a bit of PHP code as
it connects to a database? I'm trying to use the code below to let a
user know that there is a problem connecting to the database and for
whatever reason, cannot get the portion within the double quotes below
to function properly (double quotes around the code is normally not
there). PHP version is 4.1.1 so I'm wondering if perhaps the
mysql_connect_errno (have tried 'error' in place of errno) is too
advanced possibly for this php version because I can't get the code
working.

Code works fine without the error trapping portion below assuming a
connection took place but otherwise, has created an issue on one
occasion that I know of so I'd like to get the error trap in place.
thanks for any pointers.

John

"if (mysql_connect_errno())
{
echo 'Error: Could not connect to database. Please try again
later.';
exit;
}"

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to
database"); // make connection to database
mysql_select_db($DBName) or die("Unable to select database
$DBName"); // select database
if (mysql_connect_errno())
{
echo 'Error: Could not connect to database. Please try again
later.';
exit;
}
$sqlquery = "INSERT INTO $table VALUES('$id', '$time', '$month',
'$year')";
if ($results = mysql_query($sqlquery)) {
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666