RE: [PHP] sql query successful

From: Date: Wed, 18 Jul 2001 18:31:56 +0000
Subject: RE: [PHP] sql query successful
Groups: php.general 
Request: Send a blank email to php-general+get-58499@lists.php.net to get a copy of this message
I believe you should use the error function for the database you're using to check for failed queries. If you're using MySQL (which it appears that you are), you would do something like this: $sql = mysql_query("SELECT * FROM table ORDER BY rand()"); if(mysql_error()) echo "SQL not executed successfully."; else print "SQL executed successfully."; Josh Hoover KnowledgeStorm, Inc. jhoover@knowledgestorm.com Searching for a new IT solution for your company? Need to improve your product marketing? Visit KnowledgeStorm at www.knowledgestorm.com to learn how we can simplify the process for you. KnowledgeStorm - Your IT Search Starts Here > This works: > if ($connection = mysql_connect("host","username","password")) { > print "Successful connection": > } > else { > print "No connection"; > } > > But this won't work: > > if ($sql = mysql_query("SELECT * FROM table ORDER BY rand()")) { > print "SQL executed successfully."; > } > else { > print "SQL not executed successfully."; > } > > Can anyone tell me how I can tell if the SQL executed > successfully? Is > there any method besides OR DIE?

« previous php.general (#58499) next »