RE: [PHP] sql query successful

From: Date: Wed, 18 Jul 2001 18:30:33 +0000
Subject: RE: [PHP] sql query successful
Groups: php.general 
Request: Send a blank email to php-general+get-58498@lists.php.net to get a copy of this message
> -----Original Message----- > From: Tyler Longren [mailto:tyler@captainjack.com] > Sent: Wednesday, July 18, 2001 1:25 PM > To: php-general > Subject: [PHP] sql query successful > > > I've been writing database enabled site for quite a while > now. One thing I have never figured out it how to determine > if a sql query is successful. > > 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."; > } In what way doesn't this work? The above code should tell you that the query was properly formed and error-free, and was cheerfully accepted and processed by the database server. (You don't get much more successful than that...) If what you're really looking for is whether there were any rows returned by the query, then you'll want to look into the mysql_num_rows() function. --- Mark Roedel (roedelm@letu.edu) || "There cannot be a crisis next week. Systems Programmer / WebMaster || My schedule is already full." LeTourneau University || -- Henry Kissinger

« previous php.general (#58498) next »