/** * Fetch for non-mysqlnd environments * * @todo review support for custom classes * @todo review pros/cons of using store_result() * @todo fix statements using AS * * @param $int_fetch_mode * @return array|null|object|\stdClass */ private function fetchOldSchool($int_fetch_mode) { $this->obj_stmt->store_result(); $obj_meta = $this->obj_stmt->result_metadata(); $arr_fields = $obj_meta->fetch_fields(); $obj_result = NULL !== $this->str_result_class ? new $this->str_result_class() : new \stdClass(); $arr_bind_fields = array(); foreach ($arr_fields as $obj_field) { $arr_bind_fields[] =& $obj_result->{$obj_field->name}; } call_user_func_array(array($this->obj_stmt, 'bind_result'), $arr_bind_fields); if (DB::FETCH_MODE_ONE === $int_fetch_mode) { if ($this->obj_stmt->fetch()) { $mix_data = $obj_result; } else { $mix_data = NULL; } } else { $mix_data = array(); while ($this->obj_stmt->fetch()) { // Manual clone method - nasty, but required because of all the binding references // to avoid each row being === the last row in the result set $obj_row = NULL !== $this->str_result_class ? new $this->str_result_class() : new \stdClass(); foreach ($arr_fields as $obj_field) { $obj_row->{$obj_field->name} = $obj_result->{$obj_field->name}; } $mix_data[] = $obj_row; } } $this->obj_stmt->free_result(); return $mix_data; }
/** * Mysqli's binding and returning of statement values * Mysqli requires you to bind variables to the extension in order to * get data out. These values have to be references: * * @see http://php.net/manual/en/mysqli-stmt.bind-result.php * @throws Exception\RuntimeException * @return bool */ protected function loadDataFromMysqliStatement() { $data = null; // build the default reference based bind structure, if it does not already exist if ($this->statementBindValues['keys'] === null) { $this->statementBindValues['keys'] = array(); /* @var $resultResource \mysqli_result */ $resultResource = $this->resource->result_metadata(); foreach ($resultResource->fetch_fields() as $col) { $this->statementBindValues['keys'][] = $col->name; } $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); $refs = array(); foreach ($this->statementBindValues['values'] as $i => &$f) { $refs[$i] =& $f; } call_user_func_array(array($this->resource, 'bind_result'), $this->statementBindValues['values']); } if (($r = $this->resource->fetch()) === null) { if (!$this->isBuffered) { $this->resource->close(); } return false; } elseif ($r === false) { throw new Exception\RuntimeException($this->resource->error); } // dereference for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) { $this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i]; } $this->currentComplete = true; $this->nextComplete = true; $this->position++; return true; }
/** * @param \mysqli_stmt $resource * @param string $column * * @return mixed[] */ protected function fetchResource($resource, $column) { $result = []; $metadata = $resource->result_metadata(); $fields = $metadata->fetch_fields(); if (count($fields) == 0) { return []; } $variables = []; $data = []; foreach ($fields as $field) { $variables[] =& $data[$field->name]; } $resource->bind_result(...$variables); while ($resource->fetch()) { $clone = []; foreach ($data as $key => $value) { $clone[$key] = $value; } $result[] = $clone; } $resource->free_result(); $this->fixTypes($result, $fields, $column); return $result; }
/** * Get one row of data * * @return array|null * @access protected */ protected function getOneRow() { if (null === $this->cols) { $result = $this->statement->result_metadata(); if (false === $result) { return false; } $this->cols = []; // set column name foreach ($result->fetch_fields() as $col) { $this->cols[] = $col->name; } // bind values $this->vals = array_fill(0, count($this->cols), null); $refs = []; foreach ($this->vals as $i => &$f) { $refs[$i] =& $f; } call_user_func_array([$this->statement, 'bind_result'], $refs); } if ($this->statement->fetch()) { $row = []; foreach ($this->cols as $i => $col) { $row[$col] = $this->vals[$i]; } return $row; } return false; }
/** * Fetches a row from the result set. * * @param $style * @param $cursor * @param $offset * @return $data * @throws Zend_Db_Statement_Mysqli_Exception */ public function fetch($style = null, $cursor = null, $offset = null) { // fetch the next result $retval = $this->_stmt->fetch(); switch ($retval) { case null: // end of data // end of data case false: // error occurred $this->closeCursor(); return $retval; default: // fallthrough } // make sure we have a fetch mode if ($style === null) { $style = $this->_fetchMode; } // dereference the result values, otherwise things like fetchAll() // return the same values for every entry (because of the reference). $values = array(); foreach ($this->_values as $key => $val) { $values[] = $val; } // bind back to external references foreach ($this->_bindColumn as $key => &$val) { if (is_integer($key)) { // bind by column position // note that vals are 0-based, but cols are 1-based $val = $values[$key - 1]; } else { // bind by column name $i = array_search($key, $this->_keys); $val = $values[$i]; } } $data = false; switch ($style) { case Zend_Db::FETCH_NUM: $data = $values; break; case Zend_Db::FETCH_ASSOC: $data = array_combine($this->_keys, $values); break; case Zend_Db::FETCH_BOTH: $assoc = array_combine($this->_keys, $values); $data = array_merge($values, $assoc); break; case Zend_Db::FETCH_OBJ: $data = (object) array_combine($this->_keys, $values); break; default: require_once 'Zend/Db/Statement/Mysqli/Exception.php'; throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode specified"); break; } return $data; }
public function fetch_row() { $result = $this->statement->fetch(); if (false === $result) { throw new BeeHub_MySQL(self::mysqli()->error, self::mysqli()->errno); } return $result ? $this->results_array : null; }
/** * Fetches a row from the result set. * * @param int $style OPTIONAL Fetch mode for this fetch operation. * @param int $cursor OPTIONAL Absolute, relative, or other. * @param int $offset OPTIONAL Number for absolute or relative cursors. * @return mixed Array, object, or scalar depending on fetch mode. * @throws Zend_Db_Statement_Mysqli_Exception */ public function fetch($style = null, $cursor = null, $offset = null) { if (!$this->_stmt) { return false; } // fetch the next result $retval = $this->_stmt->fetch(); switch ($retval) { case null: // end of data // end of data case false: // error occurred $this->_stmt->reset(); return $retval; default: // fallthrough } // make sure we have a fetch mode if ($style === null) { $style = $this->_fetchMode; } // dereference the result values, otherwise things like fetchAll() // return the same values for every entry (because of the reference). $values = array(); foreach ($this->_values as $key => $val) { $values[] = $val; } $row = false; switch ($style) { case Zend_Db::FETCH_NUM: $row = $values; break; case Zend_Db::FETCH_ASSOC: $row = array_combine($this->_keys, $values); break; case Zend_Db::FETCH_BOTH: $assoc = array_combine($this->_keys, $values); $row = array_merge($values, $assoc); break; case Zend_Db::FETCH_OBJ: $row = (object) array_combine($this->_keys, $values); break; case Zend_Db::FETCH_BOUND: $assoc = array_combine($this->_keys, $values); $row = array_merge($values, $assoc); return $this->_fetchBound($row); break; default: /** * @see Zend_Db_Statement_Mysqli_Exception */ require_once 'Zend/Db/Statement/Mysqli/Exception.php'; throw new Zend_Db_Statement_Mysqli_Exception("Invalid fetch mode '{$style}' specified"); break; } return $row; }
/** * @return boolean|array */ private function _fetch() { $ret = $this->_stmt->fetch(); if (true === $ret) { $values = array(); foreach ($this->_rowBindedValues as $v) { $values[] = $v; } return $values; } return $ret; }
public function nextRecord() { // Skip data if out of data if (!$this->statement->fetch()) { return false; } // Dereferenced row $row = array(); foreach ($this->boundValues as $key => $value) { $row[$key] = $value; } return $row; }
/** * @return boolean|array */ private function _fetch() { $ret = $this->_stmt->fetch(); if (true === $ret) { $values = array(); foreach ($this->_rowBindedValues as $v) { // Mysqli converts them to a scalar type it can fit in. $values[] = null === $v ? null : (string) $v; } return $values; } return $ret; }
/** * Carica un indirizzo eseguendo un prepared statement * @param mysqli_stmt $stmt * @return null */ public function caricaIndirizzoDaStmt(mysqli_stmt $stmt) { if (!$stmt->execute()) { error_log("[caricaIndirizzoDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['id'], $row['destinatario'], $row['via_num'], $row['citta'], $row['provincia'], $row['cap'], $row['telefono']); if (!$bind) { error_log("[caricaIndirizzoDaStmt] impossibile" . " effettuare il binding in output"); return null; } if (!$stmt->fetch()) { return null; } $stmt->close(); return self::creaIndirizzoDaArray($row); }
/** * Carica una lista di articoli eseguendo un prepared statement * @param mysqli_stmt $stmt * @return null */ public function &caricaArticoliDaStmt(mysqli_stmt $stmt) { $articoli = array(); if (!$stmt->execute()) { error_log("[caricaArticoliDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['id'], $row['size'], $row['qty'], $row['prezzo'], $row['pizza_id']); if (!$bind) { error_log("[caricaArticoliDaStmt] impossibile" . " effettuare il binding in output"); return null; } while ($stmt->fetch()) { $articoli[] = self::creaArticoloDaArray($row); } $stmt->close(); return $articoli; }
/** * (non-PHPdoc) * @see PreparedStatement::preparedStatementFetch() */ public function preparedStatementFetch($msg = '') { if (!$this->stmt) { return false; } // first time, create an array of column names from the returned data set if (empty($this->preparedStatementResult)) { $this->resultFields = null; $this->preparedStatementResult = $this->stmt->result_metadata(); if (is_object($this->preparedStatementResult)) { $this->resultFields = $this->preparedStatementResult->fetch_fields(); } else { $this->preparedStatementResult = null; return false; } if (!empty($this->resultFields) && is_array($this->resultFields)) { $this->output_vars = $bound = array(); foreach ($this->resultFields as $k => $field) { $this->output_vars[$field->name] = null; $bound[$k] =& $this->output_vars[$field->name]; } call_user_func_array(array($this->stmt, "bind_result"), $bound); } else { $this->preparedStatementResult = null; return false; } } // Get the next results if ($this->stmt->fetch()) { $result = array(); // FIXME: figure out how to avoid copying for each result // Right now copying is needed due to the fact that the bind_result // uses references so we can not give out the same array twice, as it will be // all referenced together and all have the data of the last row foreach ($this->output_vars as $k => $v) { $result[$k] = $v; } return $result; } else { return false; } }
/** * Gets the results of the query */ private function _getResults() { $meta = $this->_query->result_metadata(); $parameters = array(); $results = array(); $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } if (version_compare(phpversion(), '5.4', '<')) { $this->_query->store_result(); } call_user_func_array(array($this->_query, 'bind_result'), $parameters); while ($this->_query->fetch()) { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } array_push($results, $x); } $this->_last_result = $results; }
/** * This helper method takes care of prepared statements' "bind_result method * , when the number of variables to pass is unknown. * * @param mysqli_stmt $stmt Equal to the prepared statement object. * * @return array The results of the SQL fetch. */ protected function _dynamicBindResults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); $meta = $stmt->result_metadata(); $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $parameters); while ($stmt->fetch()) { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } array_push($results, $x); } return $results; }
/** * This helper method takes care of prepared statements' "bind_result method * , when the number of variables to pass is unknown. * * @param mysqli_stmt $stmt Equal to the prepared statement object. * * @return array The results of the SQL fetch. */ protected function _dynamicBindResults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); $meta = $stmt->result_metadata(); // if $meta is false yet sqlstate is true, there's no sql error but the query is // most likely an update/insert/delete which doesn't produce any results if (!$meta && $stmt->sqlstate) { return array(); } $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } // avoid out of memory bug in php 5.2 and 5.3 // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119 if (version_compare(phpversion(), '5.4', '<')) { $stmt->store_result(); } call_user_func_array(array($stmt, 'bind_result'), $parameters); while ($stmt->fetch()) { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } $this->count++; array_push($results, $x); } return $results; }
/** * Returns results from a statement * @param \mysqli_stmt $stmt * @return array */ private function getResultsFromStmt($stmt) { # Get metadata for field names $meta = $stmt->result_metadata(); # Return no results if (!$meta) { return array(); } # Dynamically create an array of variables to use to bind the results $fields = array(); while ($field = $meta->fetch_field()) { $var = $field->name; ${$var} = null; $fields[$var] =& ${$var}; } # Bind Results call_user_func_array(array($stmt, 'bind_result'), $fields); # Fetch Results $i = 0; $results = array(); while ($stmt->fetch()) { $results[$i] = array(); foreach ($fields as $k => $v) { $results[$i][$k] = $v; } $i++; } $meta->free(); return $results; }
public function &creaAlbumDaStmt(mysqli_stmt $stmt) { $album = array(); if (!$stmt->execute()) { error_log("[creaAlbumDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['id'], $row['nome'], $row['autore'], $row['prezzo']); if (!$bind) { error_log("[creaAlbumDaStmt] impossibile" . " effettuare il binding in output"); return null; } while ($stmt->fetch()) { $album = self::creaAlbumDaArray($row); } $stmt->close(); return $album; }
/** * Carica un cliente eseguendo un prepared statement * @param mysqli_stmt $stmt * @return null */ private function caricaClienteDaStmt(mysqli_stmt $stmt) { if (!$stmt->execute()) { error_log("[caricaClienteDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['id'], $row['username'], $row['password'], $row['email'], $row['nome'], $row['cognome'], $row['indirizzo']); if (!$bind) { error_log("[caricaClienteDaStmt] impossibile" . " effettuare il binding in output"); return null; } if (!$stmt->fetch()) { return null; } $stmt->close(); return self::creaClienteDaArray($row); }
<?php require_once "connect.inc"; $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); $stmt = new mysqli_stmt($mysql, "SELECT 'foo' FROM DUAL"); $stmt->execute(); $stmt->bind_result($foo); $stmt->fetch(); $stmt->close(); $mysql->close(); var_dump($foo);
public function &caricaOrdiniDaStmt(mysqli_stmt $stmt) { $ordini = array(); if (!$stmt->execute()) { error_log("[caricaOrdiniDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['ordine_id'], $row['ordine_domicilio'], $row['ordine_prezzo'], $row['ordine_stato'], $row['ordine_data'], $row['cliente_id'], $row['admin_id']); if (!$bind) { error_log("[caricaOrdiniDaStmt] impossibile" . " effettuare il binding in output"); return null; } while ($stmt->fetch()) { $ordini[] = self::creaOrdineDaArray($row); } $stmt->close(); return $ordini; }
/** * Popola una lista di corsi di laurea con una query variabile * Attenzione: non popola il collegamento ai Dipartimenti * @param mysqli_stmt $stmt * @return array|\CorsoDiLaurea */ private function &inizializzaListaCorsi(mysqli_stmt $stmt) { $corsi = array(); if (!$stmt->execute()) { error_log("[inizializzaListaCorsi] impossibile" . " eseguire lo statement"); return $corsi; } $id = 0; $nome = ""; $codice = ""; if (!$stmt->bind_result($id, $codice, $nome)) { error_log("[inizializzaListaCorsi] impossibile" . " effettuare il binding in output"); return array(); } while ($stmt->fetch()) { $corso = new CorsoDiLaurea(); $corso->setCodice($codice); $corso->setNome($nome); $corso->setId($id); $corsi[] = $corso; } return $corsi; }
/** * Carica uno studente eseguendo un prepared statement * @param mysqli_stmt $stmt * @return null */ private function caricaStudenteDaStmt(mysqli_stmt $stmt) { if (!$stmt->execute()) { error_log("[caricaStudenteDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['studenti_id'], $row['studenti_nome'], $row['studenti_cognome'], $row['studenti_matricola'], $row['studenti_email'], $row['studenti_citta'], $row['studenti_via'], $row['studenti_cap'], $row['studenti_provincia'], $row['studenti_numero_civico'], $row['studenti_username'], $row['studenti_password'], $row['CdL_id'], $row['CdL_nome'], $row['CdL_codice'], $row['dipartimenti_id'], $row['dipartimenti_nome']); if (!$bind) { error_log("[caricaStudenteDaStmt] impossibile" . " effettuare il binding in output"); return null; } if (!$stmt->fetch()) { return null; } $stmt->close(); return self::creaStudenteDaArray($row); }
/** * Carica una lista di pagamenti eseguendo un prepared statement * @param mysqli_stmt $stmt * @param $flag : 1 -> un metodo | 2 -> piu' di uno * @return null */ public function caricaPagamentiDaStmt(mysqli_stmt $stmt, $flag = 1) { if (!$stmt->execute()) { error_log("[caricaPagamentiDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['id'], $row['saldo'], $row['num_carta'], $row['cod_carta'], $row['scadenza_carta'], $row['titolare_carta'], $row['tipo_carta']); if (!$bind) { error_log("[caricaPagamentiDaStmt] impossibile" . " effettuare il binding in output"); return null; } if ($flag == 1) { if (!$stmt->fetch()) { return null; } $stmt->close(); return self::creaPagamentoDaArray($row); } else { $pagamenti = array(); while ($stmt->fetch()) { $pagamenti[] = self::creaPagamentoDaArray($row); } $stmt->close(); return $pagamenti; } }
/** * Fetches a row from a result set associated with a \TYPO3\CMS\Core\Database\PreparedStatement object. * * @param int $fetch_style Controls how the next row will be returned to the caller. This value must be one of the \TYPO3\CMS\Core\Database\PreparedStatement::FETCH_* constants. If omitted, default fetch mode for this prepared query will be used. * @return array Array of rows or FALSE if there are no more rows. * @api */ public function fetch($fetch_style = 0) { if ($fetch_style == 0) { $fetch_style = $this->defaultFetchMode; } if ($this->statement instanceof \mysqli_stmt) { if ($this->buffer === NULL) { $variables = array(); $this->buffer = array(); foreach ($this->fields as $field) { $this->buffer[$field] = NULL; $variables[] =& $this->buffer[$field]; } call_user_func_array(array($this->statement, 'bind_result'), $variables); } $success = $this->statement->fetch(); $columns = $this->buffer; } else { $columns = $this->statement->fetch(); $success = is_array($columns); } if ($success) { $row = array(); foreach ($columns as $key => $value) { switch ($fetch_style) { case self::FETCH_ASSOC: $row[$key] = $value; break; case self::FETCH_NUM: $row[] = $value; break; default: throw new \InvalidArgumentException('$fetch_style must be either TYPO3\\CMS\\Core\\Database\\PreparedStatement::FETCH_ASSOC or TYPO3\\CMS\\Core\\Database\\PreparedStatement::FETCH_NUM', 1281646455); } } } else { $row = FALSE; } return $row; }
/** * This helper method takes care of prepared statements' "bind_result method * , when the number of variables to pass is unknown. * * @param mysqli_stmt $stmt Equal to the prepared statement object. * * @return array The results of the SQL fetch. */ protected function _dynamicBindResults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); $meta = $stmt->result_metadata(); // if $meta is false yet sqlstate is true, there's no sql error but the query is // most likely an update/insert/delete which doesn't produce any results if (!$meta && $stmt->sqlstate) { return array(); } $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } // avoid out of memory bug in php 5.2 and 5.3 //if (version_compare (phpversion(), '5.4', '<')) // NOTE: Always store results, because it seems that memory bug in php 5.2 and 5.3 has re-surfaced $stmt->store_result(); call_user_func_array(array($stmt, 'bind_result'), $parameters); $this->count = 0; while ($stmt->fetch()) { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } $this->count++; array_push($results, $x); } return $results; }
/** * This helper method takes care of prepared statements' "bind_result method * , when the number of variables to pass is unknown. * * @param mysqli_stmt $stmt Equal to the prepared statement object. * * @return array The results of the SQL fetch. */ protected function _dynamicBindResults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); // See http://php.net/manual/en/mysqli-result.fetch-fields.php $mysqlLongType = 252; $shouldStoreResult = false; $meta = $stmt->result_metadata(); // if $meta is false yet sqlstate is true, there's no sql error but the query is // most likely an update/insert/delete which doesn't produce any results if (!$meta && $stmt->sqlstate) { return array(); } $row = array(); while ($field = $meta->fetch_field()) { if ($field->type == $mysqlLongType) { $shouldStoreResult = true; } if ($this->_nestJoin && $field->table != $this->_tableName) { $field->table = substr($field->table, strlen(self::$prefix)); $row[$field->table][$field->name] = null; $parameters[] =& $row[$field->table][$field->name]; } else { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } } // avoid out of memory bug in php 5.2 and 5.3. Mysqli allocates lot of memory for long* // and blob* types. So to avoid out of memory issues store_result is used // https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119 if ($shouldStoreResult) { $stmt->store_result(); } call_user_func_array(array($stmt, 'bind_result'), $parameters); $this->totalCount = 0; $this->count = 0; while ($stmt->fetch()) { if ($this->returnType == 'Object') { $x = new stdClass(); foreach ($row as $key => $val) { if (is_array($val)) { $x->{$key} = new stdClass(); foreach ($val as $k => $v) { $x->{$key}->{$k} = $v; } } else { $x->{$key} = $val; } } } else { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } } $this->count++; array_push($results, $x); } if ($shouldStoreResult) { $stmt->free_result(); } $stmt->close(); // stored procedures sometimes can return more then 1 resultset if ($this->mysqli()->more_results()) { $this->mysqli()->next_result(); } if (in_array('SQL_CALC_FOUND_ROWS', $this->_queryOptions)) { $stmt = $this->mysqli()->query('SELECT FOUND_ROWS()'); $totalCount = $stmt->fetch_row(); $this->totalCount = $totalCount[0]; } if ($this->returnType == 'Json') { return json_encode($results); } return $results; }
/** * Carica un docente eseguendo un prepared statement * @param mysqli_stmt $stmt * @return null */ private function caricaAdminDaStmt(mysqli_stmt $stmt) { if (!$stmt->execute()) { error_log("[caricaAdminDaStmt] impossibile" . " eseguire lo statement"); return null; } $row = array(); $bind = $stmt->bind_result($row['admin_id'], $row['admin_username'], $row['admin_password'], $row['admin_nome'], $row['admin_cognome'], $row['admin_via'], $row['admin_civico'], $row['admin_cap'], $row['admin_citta'], $row['admin_telefono']); if (!$bind) { error_log("[caricaAdminDaStmt] impossibile" . " effettuare il binding in output"); return null; } if (!$stmt->fetch()) { return null; } $stmt->close(); return self::creaAdminDaArray($row); }
/** * This helper method takes care of prepared statements' "bind_result method * , when the number of variables to pass is unknown. * * @param mysqli_stmt $stmt Equal to the prepared statement object. * * @return array The results of the SQL fetch. */ protected function _dynamicBindResults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); $meta = $stmt->result_metadata(); // if $meta is false yet sqlstate is true, there's no sql error but the query is // most likely an update/insert/delete which doesn't produce any results if (!$meta && $stmt->sqlstate) { return array(); } $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] =& $row[$field->name]; } $stmt->store_result(); call_user_func_array(array($stmt, 'bind_result'), $parameters); while ($stmt->fetch()) { $x = array(); foreach ($row as $key => $val) { $x[$key] = $val; } $this->count++; array_push($results, $x); } return $results; }
/** * Fetches the result from a prepared query. * * @param \MYSQLi_STMT $query The prepared query to fetch the result from. * * @return string[] The result array or null in case we have no result. * * @author Christian Achatz * @version * Version 0.1, 09.03.2010<br /> */ private function fetchBindResult(\mysqli_stmt $query) { $result = null; do { $metaData = $query->result_metadata(); // in case the meta data is not present (e.g. for INSERT statements), // we cannot fetch any data. thus we return null to indicate no result if ($metaData === false) { break; } $resultRow = []; $resultParams = []; while ($field = $metaData->fetch_field()) { $resultParams[] =& $resultRow[$field->name]; } $bindResult = []; call_user_func_array([&$query, 'bind_result'], $resultParams); while ($query->fetch()) { $currentRow = []; foreach ($resultRow as $key => $val) { $currentRow[$key] = $val; } $bindResult[] = $currentRow; } $result[] = $bindResult; } while ($query->more_results() && $query->next_result()); // for sprocs return count($result) === 1 ? $result[0] : $result; }