PHP Classes

Mysqli returning correct number of rows but not results

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  Learn with a PHP OAut...  >  All threads  >  Mysqli returning correct number of...  >  (Un) Subscribe thread alerts  
Subject:Mysqli returning correct number of...
Summary:Using database_oauth_client.php & mysqli_oauth_client.php
Messages:3
Author:Graham Moy
Date:2017-04-01 14:09:32
 

  1. Mysqli returning correct number of...   Reply   Report abuse  
Picture of Graham Moy Graham Moy - 2017-04-01 14:09:32
I've added a table 'roster' to the database and am using the $this->query() to access it. The table contains the following:
id player team
116 6 2
117 6 3
118 3 5

When running query:
$parameters = array(
'i', 0
);
$result_types = array( 'i');
$this->Query('SELECT id FROM roster WHERE player <> ?', $parameters, $results, $result_types)

$results contains:
Array ( [0] => Array ( [0] => Array ( [0] => 118 ) [1] => Array ( [0] => 118 ) [2] => Array ( [0] => 118 ) ) )

I was expecting:
Array ( [0] => Array ( [0] => Array ( [0] => 116 ) [1] => Array ( [0] => 117 ) [2] => Array ( [0] => 118 ) ) )

It seems to return the correct number of rows, 3 in this case, but populate all rows with the data from the last returned row! What am I doing wrong here? Many thanks in advance for your help.

Graham.

  2. Re: Mysqli returning correct number of...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2017-04-01 22:03:49 - In reply to message 1 from Graham Moy
This does not seem to have to do with the OAuth classes.

Anyway, it seems that you are missing the ORDER BY clause in the SQL statement. If you do not specify an order clause, the server will return records by an unpredictable order.

  3. Re: Mysqli returning correct number of...   Reply   Report abuse  
Picture of Graham Moy Graham Moy - 2017-04-03 10:07:28 - In reply to message 2 from Manuel Lemos
Hi Manuel,

Thank you for taking the time to answer.

This question relates to mysqli_oauth_cleint.php and specifically the Query function within it. No matter how many results it returns (normally this is only one result) it populates ALL results with the value of the LAST result. When only one result is returned this obviously works fine because it populates the only result with the value of the last result. So something is happening inside that Query function to make ALL the rows contain the same LAST value, and that's not right but isn't noticed when only one result is returned.

I take your point about the ORDER BY but I'm not bothered if the results are returned randomly or not in this instance. And more to the point it won't make a difference if the results are all the same; which they are and they shouldn't be.

Maybe I'm calling the function incorrectly in the first instance? Thanks again for your help.

Graham