X
X
Xren2018-06-09 13:54:35
PHP
Xren, 2018-06-09 13:54:35

MySQLi query result does not contain first row?

I am migrating from mysql to mysqli. It would seem banal, but I stumbled upon a problem. mysqli query returns one line less, or rather skips the first line, while mysql and phpmyadmin process the same query correctly.
Half a day I poke the engine, nothing helps. I decided to write a separate test script with only a request (so that the engine would definitely not affect the result in any way), the effect is the same, the first line is ignored.

$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
    
if ($mysqli->connect_error) {
  echo 'Error: Could not make a database link (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error;
}

$mysqli->query("SET NAMES 'utf8'");
$mysqli->query("SET CHARACTER SET utf8");
$mysqli->query("SET CHARACTER_SET_CONNECTION=utf8");
$mysqli->query("SET SQL_MODE = ''");


$result = $mysqli->query("SELECT * FROM setting WHERE qwe = '0'");
print_r($result); //mysqli_result Object ( [current_field] => 0 [field_count] => 6 [lengths] => [num_rows] => 535 [type] => 0 )

There are 536 objects in the database, the very first one was skipped. In queries where one row is returned mysqli returns emptiness, mysql returns one row as expected.
Tested on php 5.3.29/ php 5.4.45 and MySQL 5.7.22.
I really don't understand what a poltergeist is. What to do then? Porting to PDO is not an option. In the future I want to switch to php7+.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question