php - Possibilites @mysql_affected_rows return Values? -


this question has answer here:

can please tell me possibilities of return values @mysql_affected_rows. because checking if(@mysql_affected_rows()). in case returns 1(sucess) or 0(not sucess). worked correctly. in cases returns value other 0 if not success on updation.

i dont know returns. come loop. inside loop trying insert data. shows duplication error on sql that. reference check below code please,

$sqlu = sprintf("update %s set count = count + 1                             id = %d", 'table', 123); mysql_query($sqlu); if(!@mysql_affected_rows()) {     $sqli = sprintf("insert %s (id) values (%d)",                                 'table', 123);     mysql_query($sqli); } 

first, mysql_* functions deprecated. mysql_affected_rows() seems return integer in cases. returns -1 if query failed.

what need instead of mysql_affected_rows() proper query not open race conditions.

insert table (id, count) values (123, 0) on duplicate key update count = count + 1


Comments