Mysql_affected_rows () returns -1

When executing an SQL statement such as INSERT INTO table... ON DUPLICATE KEY UPDATE ... I rely on mysql_affected_rows () to determine if an insert or update has been performed. as the mysql site at http://dev.mysql.com/doc/refman/5.1/en/mysql-affected-rows.html , it reports:

For INSERT ... ON DUPLICATE KEY UPDATE statements, the value of the affected rows is 1 if the row is inserted in a new row and 2 if the existing row is updated.

Everything worked fine until we upgraded to MySQL 5.1.16, when many queries now had mysql_affected_rows () returning MINUS ONE (-1)

The proposed solution on the MySQL website at http://dev.mysql.com/doc/refman/5.1/en/mysql-store-result.html should call the mysql_store_result () function after each execution of the mysql_query () function to request a choice.

However, PHP does not have such a function.

How can I get mysql_affected_rows () to work correctly with PHP and MySQL 5.1.16?

+5
source share
2 answers

, mysql_affected_rows() -1, , (. ). , , mysql_error(), mysql_query(), , .

store_result, :

PHP MySQL store_result, MySQLi . . http://php.net/manual/en/mysqli.store-result.php

mysql_xxx mysqli_xxx, .

PHP , MySQLi PHP 5.0. , PHP 5.1, , .

+4

mysql_affected_rows -1, . / . . .

+2

All Articles