php - Select and call_user_func_array issue -


i've function:

private function db_bind_array($stmt, &$row) {   $md = $stmt->result_metadata();   $param = array();   while($field = $md->fetch_field()) { $param[] = &$row[$field->name];}   return call_user_func_array(array($stmt, 'bind_result'), $param); } private function db_query($sql, $bind_param, $param) {   if($stmt = $this->conn->prepare($sql)) {   if(!$bindret = call_user_func_array(array($stmt,'bind_param'),   array_merge(array($bind_param), $param))) $this->terminate();   if(!$stmt->execute()) $this->terminate();   $res = array();   if($this->db_bind_array($stmt, $res)) return array($stmt, $res);   } }  protected function select($recs, $table, $where, $bind_param, $param, $order_by = '', $sort = '', $limit = 1) {   if($order_by != '') $order_by = 'order '.$order_by;   $sql = "select $recs $table $where $order_by $sort limit $limit";   return $this->exeselect($sql, $bind_param, $param); } private function exeselect($sql, $bind_param, $param) {   if($res = $this->db_query($sql, $bind_param, array(&$param))) {   $stmt = $res[0]; $row  = $res[1];   while($stmt->fetch()) {$this->row = $row; return $row;}   $stmt->close();   } } 

and use it: $row = $this->select('id, name, title, 'articles', id >, 'i', 10, 'desc', '', 10)

the problem returns 1 record instead of 10. what's problem? thanks

the problem line: while($stmt->fetch()) {$this->row = $row; return $row;}. return result. build array before return it.

private function exeselect($sql, $bind_param, $param) {     $ret = array();     if($res = $this->db_query($sql, $bind_param, array(&$param))) {         $stmt = $res[0]; $row  = $res[1];         while($stmt->fetch()) {$ret[] = $row; }         $stmt->close();     }     return $ret; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -