php - fetching multiple row in mysqli -


i working on little project, unfortunately, hosting not support package mysqldn, therefore unable work fetch_all() function. block of code thats causing headaches me.

public function fetch($type = 'object') {     if (isset($this->result))     {         switch ($type)         {             case 'array':                  //fetch row array                 //$row = $this->result->fetch_all();                 $rows = array();                 while($row = $this->result->fetch_assoc())                 {                     $rows[] = $row;                 }             break;              case 'object':              //fall through...              default:                  //fetch row object                 $row = $this->result->fetch_object();                 break;         }          return $rows;     }      return false; } 

as said previously, can not use fetch_all() function on current hosting. therefore, there alternative function? can do?

the native mysqli->fetch() function return next row in resultset until reaches end.

just call once if want next row, or can include in loop if want rows, example

while($row = $this->result->fetch()) {     //do $row } 

edit: relates fetching results prepared statements only, , work $this->result held result of store_result() after execution of prepared statement.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -