Jump to content

return value of sql query


wlogeshwaran

Recommended Posts

This piece of code deletes the row having time less than system time.

 

1) $tim=time(); $timer=time()+100;

2) mysql_query("delete from test where time < $tim ");

3) mysql_query("update test set time=$timer where status='Waiting');

 

 

I want to execute line 3 , only when line 2 actually deletes a row in the table.

 

Suggest me an idea or tell me what i have to do to check whether line 2 has actually deleted the row. Tell me the return value of the sql query once it get executed.

Link to comment
https://forums.phpfreaks.com/topic/233803-return-value-of-sql-query/
Share on other sites

You could also tryusing an if :

$tim=time(); $timer=time()+100;
$del = mysql_query("delete from test where time < $tim ");
$act = mysql_num_rows($del);
if ($act != 0 ){mysql_query("update test set time=$timer where status='Waiting');}

 

Not something I have tested, but should work I think.

You would also need to check if mysql_affected_rows returned a number greater-than zero because it will return a -1 when the query itself failed due to an error and a != 0 comparison would match a -1

 

I never knew that, I thought that it was a 0/1 bit flag.  Thanks for that PFM.

 

Oh, and miko - I missed you  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.