I have a baffling problem trying to query a MySQL database using mysqli. I can only use the fetch_row method - the fetch_assoc doesn't work.
I don't think it's relevant but the code fragments below are called from a singleton DBManager class within a try{} block.
So this works fine.....
$result = $this->_dbConnection->query('SELECT name, shortname FROM real_club');
while ($row = $result->fetch_row())
printf ('%s %s<br>', $row[0], $row[1]);
But calling any of the other fetch functions (e.g. fetch_assoc) doesn't work, whether calling them procedurally or using the class interface. (NB $result->fetch_array(MYSQLI_NUM) is OK too.
So if I replace the fetch in the above code with the following
while ($row2 = $result->fetch_assoc())
echo "hello world<br>";
Then I end up with a Page Load Error - "Network Timeout - The operation timed out when attempting to contact www.localhost.com"
I can get by with the fetch_row, but would prefer to use fetch_assoc.
$finfo = $result->fetch_fields() works completely as expected, so I think the DB is working as I'd expect it to. Fields returned by it are as follows:
Table: real_club
Name: name
Flags: 4097
Type: 253
I don't know of any reason why fetch_row() should work but not fetch_assoc(). All I can think of without more info to go by is that the client mysql programs (e.g. the DLLs if a Windows installation) are somehow corrupt or missing. You might want to try to find the smallest, simplest piece of code that will replicate the error and post it here to see if we can detect anything "odd" about it -- or doing so might help you find the problem yourself. (Be sure to turn on all error_reporting.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
This file replicates the problem. Set $fetchRow = true and it works exactly as expected. Set $fetchRow to false and the Network Timeout error appears.
NB To run the program I type localhost/sqli_issue.php into the browser. When I get the problem the URL becomes 'http://www.localhost.com/sqli_bug.php' after the timeout (about 30s).
Ran OK for me locally (I only changed the DB login credentials, database name, and table/column names to match an existing DB). I'm running PHP 5.2.9, MySQL 5.1.32, Apache 2.2.11 on Windows Vista.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks