Re: Re: Mysql DB connect failure

From: Date: Mon, 24 Feb 2003 07:15:43 +0000
Subject: Re: Re: Mysql DB connect failure
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-136848@lists.php.net to get a copy of this message
better to use something like mysql_connect("localhost", "test1", "test1")||die(mysql_error()); because you will make smaller code that way killing the script instantly when connection is refused and you will still get the same message: user access denied for 'root@localhost' using password:(yes) in either case die would be better to use than testing a link variable since in very large amounts of hits on the db that way could cause a test to fall through and do something really uninteresting.. at least thats my experience with that... so if i purposfully make an error: mysql_connect("localhost", "root", "")||die(mysql_error()); i get the message above about the error ----- Original Message ----- From: "Hans Prins" <HPrins@xgn.nu> To: <php-general@lists.php.net> Sent: Friday, February 21, 2003 11:07 AM Subject: Re: [PHP] Re: Mysql DB connect failure > > Would you care to explain to the rest of the list how you intend to use > > mysql_error () to return connection failure information? > > > > It returns the text of the error message from previous MySQL operation > > Description: string mysql_error ( [resource link_identifier]) > > > > Seems to me that without a connection, we wouldn't have a valid > > link_identifier. > > maybe so, but it works nonetheless............. > > if for example the username stated in the connection initialization was > wrong it will print an error like: > > "Access denied for user: 'username@localhost' (Using password: YES)" > > MI, > > my code would look somethign like this: > > $link = @mysql_pconnect("localhost", "test1", "test1"); > > // If connection failed... > if (!$link) { > // Inform user of error and quit > print "Couldn't connect to database server<br>\n"; > print mysql_error(); > exit; > } > > > > "Jason K Larson" <jlarson@candlefire.org> schreef in bericht > news:3E564B92.4070703@candlefire.org... > > Would you care to explain to the rest of the list how you intend to use > > mysql_error () to return connection failure information? > > > > It returns the text of the error message from previous MySQL operation > > Description: string mysql_error ( [resource link_identifier]) > > > > Seems to me that without a connection, we wouldn't have a valid > > link_identifier. > > > > What you probably should attempt going for is getting something back > > from PHP itself regarding the error returned when the mysql_connect > failed. > > > > Here's a snippet from: > > > > http://www.php.net/manual/en/language.operators.errorcontrol.php > > > > If the track_errors feature is enabled, any error message generated by > > the expression will be saved in the global variable $php_errormsg. This > > variable will be overwritten on each error, so check early if you want > > to use it. > > > > Hope that clears things up a bit. > > > > Regards, > > Jason k Larson > > > > > > > > Hans Prins wrote: > > > did you try: > > > print mysql_error(); > > > > > > "Ml" <slickmik@eden.rutgers.edu> schreef in bericht > > > news:20030221152240.57775.qmail@pb1.pair.com... > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.443 / Virus Database: 248 - Release Date: 1/11/2003

« previous php.general (#136848) next »