> -----Original Message-----
> From: Tyler Longren [mailto:[EMAIL PROTECTED]]
> 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 ([EMAIL PROTECTED])  ||  "There cannot be a crisis next week.
Systems Programmer / WebMaster  ||   My schedule is already full."
     LeTourneau University      ||                    -- Henry Kissinger


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to