...

View Full Version : error function does not run for mysql



zodehala
01-05-2008, 10:11 AM
why doesnot this function run (erro message i have defined does not occur)



ini_set('display_errors', false);
function db_error($no){
"Error No :".$no."<br/>"."Error :".mysql_error();
}

$link = mysql_connect('localhost', 'root', '12');
if (!$link) {
die( db_error(mysql_errno()));
}
echo 'Connected successfully';
mysql_close($link);

Inigoesdr
01-05-2008, 11:00 AM
Because the error function isn't returning anything to die():

function db_error($no)
{
return 'Error No : ' . $no . '<br/>Error : ' . mysql_error();
}
You don't really need a function for this simple code, by the way. You could just place the code(replace $no with mysql_error()) in the error function inside of the die(); (http://php.net/die)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum