error catch on db connect?

In my backend I have written a script which allows one to setup his database info on the server, however when a username or pw is entered which is not registered with mysql I’d like for there to be a nice message stating such instead of the usual error/warning mysql gives… I was thinking that perhaps I could ommit the error code altogether (“or trigger_error(mysql_error(),E_USER_ERROR”) and try something like an if statement using the connection ($dbc = mysql_pconnect($hostname_dbc, $username_dbc, $password_dbc)") as a condition which has to be true… else, an echo stating the error… I hope this makes sense… :o

anyhow, as I was cautioned by one here, php has turned out to be quite fun… lol :wink:

ah, so I have succeeded by using:

[code]if (($dbc = mysql_pconnect($hostname_dbc, $username_dbc, $password_dbc)) == true )
mysql_select_db ($database_dbc);
execute some queries;

else {

echo “incorrect connection dada provided!!!”
} [/code]

but still It returns a warning above the echo… is there any way to supress this? thanks…

What I personally do -

testing -
   in the php.ini file have display_errors = On
   On the page:
      $dbc = mysql_pconnect($hostname_dbc, $username_dbc, $password_dbc);
      if (!$dbc)
         echo 'Error: There was a problem making a connection. ';
         echo 'Invalid connection data provided. ';
         // In Production this is removed
         echo mysql_error();
production - 
   in the php.ini file have display_errors = Off
   comment out the mysql_error code

cool thanks! 8)

Sponsor our Newsletter | Privacy Policy | Terms of Service