1

I'm getting an odd result, the following is the state of the mysqli object after a simple update query:

"UPDATE charstate SET name = '-', type = 'The Homemaker' WHERE gameno = 1"

As you see the affected_rows = -1 but... the info is "Rows matched: 3 Changed: 3 Warnings: 0" And the query has updated the database. I am using mysqli->affected_rows to check the success which is returning -1 and failing my test but that is incorrect.

Any ideas?

mysqli object {
  affected_rows => (int) -1
  client_info => (string) mysqlnd 5.0.10 - 20111026 - $Id: 
  client_version => (int) 50010
  connect_errno => (int) 0
  connect_error => null
  errno => (int) 0
  error => (string)
  error_list => array(0)
  field_count => (int) 0
  host_info => (string) 127.0.0.1 via TCP/IP
  info => (string) Rows matched: 3  Changed: 3  Warnings: 0
  insert_id => (int) 0
  server_info => (string) 5.5.27
  server_version => (int) 50527
  stat => (string) Uptime: 11431  Threads: 6  Questions: 542  Slow queries: 0  Opens: 52  Flush tables: 1  Open tables: 2  Queries per second avg: 0.047
  sqlstate => (string) 00000
  protocol_version => (int) 10
  thread_id => (int) 114
  warning_count => (int) ...
iss42
  • 2,720
  • 3
  • 21
  • 37
  • Are you very sure that the query really did succeed? The docs clearly say that an "affected_rows" value of -1 means that the query returned some kind of error. – CmdrMoozy May 31 '13 at 19:02
  • @Cmdr I thought the same thing, but `errno` is clearly `0`, it can't be that – Pekka May 31 '13 at 19:03
  • 3
    Maybe it's this problem? http://stackoverflow.com/questions/12569862/php-mysqli-statement-returns-a-single-row-1-rows-affected-and-no-error Are you using mysqli's prepared statements? – CmdrMoozy May 31 '13 at 19:05
  • Nope, not a prepared statement, just mysqli->query($query). I do have the mysqli object in a parent class, so it is actually $this->mysqli->query($query); – iss42 May 31 '13 at 19:27

1 Answers1

0

This behavior above appears when using "root" as the mysql user login (without password). When using another user the affected_rows is correctly given.

Weird! Seems this is a bug of some sort in mysql or PHP. I don't know which or how to report that to whom.

iss42
  • 2,720
  • 3
  • 21
  • 37
  • The described behaviour is indeed strange. what versions of PHP and mySQL are you using? Make sure you're on the latest patch releases of both before even thinking of submitting a bug report. If you do submit a bug report, I'd submit it to PHP in the first instance, unless you can replicate the problem through another method outside of PHP. Oh, and doing *anything* with "root" and no password is a really bad idea. Even on your dev box. Just sayin'. – Spudley May 31 '13 at 21:32
  • MySQL version 5.5.27 and PHP version 5.4.7 - this is under XAMPP on Windows though, I haven't tested elsewhere in the exact conditions. Still pretty odd. – iss42 Jun 15 '13 at 22:24