tags:

views:

57

answers:

1

Hello,

i'm totally new to mysqli and i took a generated code and adapted it for my need.

UPDATED :

public function getServeurByName($string) {

        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where GSP_nom=?");
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 's', $string);        
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);
        $this->throwExceptionOnError();


        $rows = array();

        mysqli_stmt_bind_result($stmt, $row->idServ, $row->GSP_nom, $row->IPserv, $row->port, $row->tickrate, $row->membre, $row->nomPays, $row->finContrat, $row->actif, $row->timestamp, $row->type, $row->jeux, $row->slot, $row->ipClient, $row->essai, $row->reussite, $row->echec, $row->valide, $row->email);

        while (mysqli_stmt_fetch($stmt)) {
          $row->timestamp = new DateTime($row->timestamp);
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->idServ, $row->GSP_nom, $row->IPserv, $row->port, $row->tickrate, $row->membre, $row->nomPays, $row->finContrat, $row->actif, $row->timestamp, $row->type, $row->jeux, $row->slot, $row->ipClient, $row->essai, $row->reussite, $row->echec, $row->valide, $row->email);
        }

        mysqli_stmt_free_result($stmt);
        mysqli_close($this->connection);

        return $rows;
    }

the problem, this example i took the template on returns only one row instead of all the records.

how to fix that please ?

edit2 :

print_r($row) show :
stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) stdClass Object ( [idServ] => 0 [GSP_nom] => [IPserv] => [port] => 0 [tickrate] => 0 [membre] => [nomPays] => [finContrat] => [actif] => 0 [timestamp] => [type] => 0 [jeux] => 0 [slot] => 0 [ipClient] => [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 0 [email] => ) 

/ print_r($rows); shows

Array ( [0] => stdClass Object ( [idServ] => 190 [GSP_nom] => bc2x [IPserv] => 85.234.212.181 [port] => 27015 [tickrate] => 100 [membre] => [nomPays] => Belgique [finContrat] => 20111231 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 1 [jeux] => 1 [slot] => 34 [ipClient] => 81.240.221.92 [essai] => 6 [reussite] => 0 [echec] => 0 [valide] => 1 [email] => ) [1] => stdClass Object ( [idServ] => 191 [GSP_nom] => bc2x [IPserv] => 85.234.212.185 [port] => 27028 [tickrate] => 100 [membre] => LowReal [nomPays] => Belgique [finContrat] => 20111127 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 2 [jeux] => 1 [slot] => 11 [ipClient] => 81.240.221.92 [essai] => 6 [reussite] => 0 [echec] => 0 [valide] => 1 [email] => ) [2] => stdClass Object ( [idServ] => 192 [GSP_nom] => bc2x [IPserv] => 91.121.27.79 [port] => 27033 [tickrate] => 100 [membre] => LowReal [nomPays] => Belgique [finContrat] => 20110915 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 2 [jeux] => 1 [slot] => 11 [ipClient] => 81.240.221.92 [essai] => 6 [reussite] => 0 [echec] => 0 [valide] => 1 [email] => ) [3] => stdClass Object ( [idServ] => 443 [GSP_nom] => bc2x [IPserv] => 193.105.73.249 [port] => 27069 [tickrate] => 100 [membre] => [nomPays] => France [finContrat] => 20111231 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 2 [jeux] => 1 [slot] => 12 [ipClient] => 81.241.72.19 [essai] => 6 [reussite] => 2 [echec] => 6 [valide] => 1 [email] => [email protected] ) [4] => stdClass Object ( [idServ] => 468 [GSP_nom] => bc2x [IPserv] => 213.246.45.17 [port] => 27005 [tickrate] => 100 [membre] => admin [nomPays] => France [finContrat] => 20110302 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 1 [jeux] => 1 [slot] => 12 [ipClient] => 127.0.0.1 [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 1 [email] => [email protected] ) [5] => stdClass Object ( [idServ] => 470 [GSP_nom] => bc2x [IPserv] => 213.246.45.17 [port] => 27005 [tickrate] => 100 [membre] => admin [nomPays] => Allemagne [finContrat] => 20110811 [actif] => 1 [timestamp] => DateTime Object ( ) [type] => 2 [jeux] => 1 [slot] => 12 [ipClient] => 127.0.0.1 [essai] => 0 [reussite] => 0 [echec] => 0 [valide] => 1 [email] => [email protected] ) ) 
+1  A: 

I haven't used mysqli myself, but to me it looks like the problem is here:

if(mysqli_stmt_fetch($stmt)) {
  $row->timestamp = new DateTime($row->timestamp);
  return $row;
} else {
  return null;
}

Maybe something like this (no guarantee this will work without modification, and it definitely breaks your contract of returning null on 0 results by returning an empty array .. adjust to your needs):

$arr = array();
while (mysqli_stmt_fetch($stmt)) {
    // copy data from $row to $arr
}
return $arr;

If you encounter problems with the contents of $arr's elements, maybe the discussion here can help: http://php.net/manual/en/mysqli-stmt.fetch.php

Lauri Lehtinen
Getting one line of '0'. Any tracks where do i need to do changes ? Thanks
Tristan
To debug, I'd do a print_r($row); inside the while loop and print_r($arr); before returning, and try to go from there.
Lauri Lehtinen
i didn't manage to debug this. If you have an idea please, i'm stuck here.
Tristan
What does print_r($row) show? You could maybe update your question with what you have tried and found out so far.
Lauri Lehtinen
see my : update 1 + update 2 please all information are in there ;)Thank you. Guess the problem is in flex since the correct values are in $rows
Tristan