本文整理汇总了PHP中mysqli_stmt::get_result方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt::get_result方法的具体用法?PHP mysqli_stmt::get_result怎么用?PHP mysqli_stmt::get_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli_stmt
的用法示例。
在下文中一共展示了mysqli_stmt::get_result方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchNative
/**
* Fetch using mysql native driver functions
*
* Note: seems you CANNOT pass NULL or blank string to fetch_object()
* you must actually NOT pass anything
*
* @param $int_fetch_mode
* @return array|object|\stdClass
*/
private function fetchNative($int_fetch_mode)
{
/** @var $obj_result \mysqli_result */
$obj_result = $this->obj_stmt->get_result();
if (DB::FETCH_MODE_ONE === $int_fetch_mode) {
if ($this->str_result_class) {
$mix_data = $obj_result->fetch_object($this->str_result_class);
} else {
$mix_data = $obj_result->fetch_object();
}
} else {
$mix_data = array();
if ($this->str_result_class) {
while ($obj_row = $obj_result->fetch_object($this->str_result_class)) {
$mix_data[] = $obj_row;
}
} else {
while ($obj_row = $obj_result->fetch_object()) {
$mix_data[] = $obj_row;
}
}
}
$obj_result->free();
return $mix_data;
}
示例2: executar
/**
* executar
* Recebe os dados, monta o bind_param e executa.
*
* @param array
* @throws Exception
*/
protected function executar(array $dados)
{
/** @var array */
$params = $this->prepararDados($dados);
/** Passa os paramentros ao bind_param */
if (count($dados) > 0) {
if ($this->stmt) {
call_user_func_array(array($this->stmt, 'bind_param'), $this->makeValuesReferenced($params));
} else {
throw new Exception("Erro ao executar \"{$this->mysqli->error}\"", $this->mysqli->errno);
}
}
/** Executa a consulta e verifica se ocorreu algum erro */
if (!$this->stmt->execute()) {
throw new Exception("Erro ao executar: (" . $this->stmt->error . ") ", $this->stmt->errno);
}
/** Preenche o array de dados caso haja algum retorno */
$this->result = array();
$r = $this->stmt->get_result();
if ($r) {
while ($row = $r->fetch_assoc()) {
$this->result[] = $row;
}
}
/** Fecha o stamtment e a conexao com o banco */
$this->stmt->close();
$this->mysqli->close();
}
示例3: doLoginWithPostData
private function doLoginWithPostData()
{
// check login form contents
if (empty($_POST['email'])) {
$this->errors[] = "Email field was empty.";
} else {
if (empty($_POST['password'])) {
$this->errors[] = "Password field was empty.";
} else {
if (!empty($_POST['email']) && !empty($_POST['password'])) {
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// change character set to utf8 and check it
if (!$this->db_connection->set_charset("utf8")) {
$this->errors[] = $this->db_connection->error;
}
// if no connection errors (= working database connection)
if (!$this->db_connection->connect_errno) {
// escape the POST stuff
$email = $this->db_connection->real_escape_string($_POST['email']);
// database query, getting all the info of the selected user (allows login via email address in the
// username field)
$sql = new mysqli_stmt($this->db_connection, "SELECT id, first_name, last_name, email, password, privilege FROM users WHERE email = ?;");
$sql->bind_param("s", $_POST['email']);
$sql->execute();
$result_of_login_check = $sql->get_result();
// if this user exists
if ($result_of_login_check->num_rows == 1) {
// get result row (as an object)
$result_row = $result_of_login_check->fetch_object();
// using PHP 5.5's password_verify() function to check if the provided password fits
// the hash of that user's password
if (password_verify($_POST['password'], $result_row->password)) {
// write user data into PHP SESSION (a file on your server)
$_SESSION['id'] = $result_row->id;
$_SESSION['first_name'] = $result_row->first_name;
$_SESSION['last_name'] = $result_row->last_name;
$_SESSION['email'] = $result_row->email;
// $_SESSION['privilege'] = $result_row->privilege;
$_SESSION['user_login_status'] = 1;
$this->messages[] = "You have logged in successfully!";
} else {
$this->errors[] = "Wrong password. Try again.";
}
} else {
$this->errors[] = "This user does not exist.";
}
} else {
$this->errors[] = "Database connection problem.";
}
}
}
}
}
示例4: execute
/**
* Execute the prepared statement
*
* @param array $parameters
* @return \Attw\Db\Statement\MySQLiStatement
*/
public function execute(array $parameters = array())
{
if (count($this->bindParam) > 0 || count($parameters) > 0) {
$this->bindParamOfMySQLi($parameters);
}
$this->verifyMySQLiErrorsAndThrowException();
if (!$this->stmt->execute()) {
StatementException::mysqliStmtError($this->stmt->error, $this->stmt->errno);
}
$this->result = $this->stmt->get_result();
return $this;
}
示例5: getFetchArrays
/**
* Get all array data
*
* @return array
*/
public function getFetchArrays()
{
$data = array();
if ($this->resource instanceof \mysqli_result) {
$result = $this->resource;
} else {
if ($this->resource instanceof \mysqli_stmt) {
$result = $this->resource->get_result();
} else {
if ($this->resource instanceof \mysqli) {
$result = $this->resource->store_result();
}
}
}
while ($row = $result->fetch_array(\MYSQLI_ASSOC)) {
$data[] = $row;
}
return $data;
}
示例6: RunAndFetchObjects
/** Takes a prepared statement and fetches all objects from it
* @param string $className Name of the class contained in table
* @return array of objects
*/
private function RunAndFetchObjects($className, mysqli_stmt $stmt)
{
$result = $stmt->execute();
$ret = array();
$result = $stmt->get_result();
while ($object = $result->fetch_object()) {
//NOTE! requires that we have a pk in the object not that obvious
$ret[] = $object;
//$ret[$object -> uid] = $object;
}
$stmt->close();
return $ret;
}
示例7: isUserVerified
function isUserVerified($mysqli, $userID)
{
$stmt = new mysqli_stmt($mysqli, "SELECT verified FROM users WHERE id = ?");
if ($stmt) {
$stmt->bind_param('i', $userID);
$stmt->execute();
$result = $stmt->get_result()->fetch_object();
if ($result->verified == TRUE) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
示例8: getHoldingsFromKohaDB
/**
* Load all items from the database.
*
* Uses some code based on C4::Items GetItemsInfo in koha
*
* @param $recordId
* @return array
*/
private function getHoldingsFromKohaDB($recordId)
{
$holdingsFromKoha = array();
$this->initDatabaseConnection();
if ($this->getHoldingsStmt == null) {
$sql = "SELECT itemnumber, barcode, itype, holdingbranch, location, itemcallnumber, onloan, ccode, itemnotes, enumchron, damaged, itemlost, wthdrawn, restricted FROM items where biblionumber = ? AND suppress = 0";
$this->getHoldingsStmt = mysqli_prepare($this->dbConnection, $sql);
}
$this->getHoldingsStmt->bind_param("i", $recordId);
if (!$this->getHoldingsStmt->execute()) {
global $logger;
$logger->log("Unable to load holdings from Koha ({$this->getHoldingsStmt->errno}) {$this->getHoldingsStmt->error}", PEAR_LOG_ERR);
} else {
//Read the information
$results = $this->getHoldingsStmt->get_result();
while ($curRow = $results->fetch_assoc()) {
if ($curRow['itype'] == 'EAUDIO' || $curRow['itype'] == 'EBOOK' || $curRow['itype'] == 'ONLINE') {
continue;
}
$curItem = array();
$curItem['type'] = 'holding';
$curItem['id'] = $curRow['itemnumber'];
$curItem['barcode'] = $curRow['barcode'];
$curItem['itemType'] = mapValue('itype', $curRow['itype']);
$curItem['locationCode'] = $curRow['location'];
$curItem['library'] = mapValue('location', $curRow['holdingbranch']);
$curItem['location'] = $curRow['location'];
$curItem['collection'] = mapValue('ccode', $curRow['ccode']);
$curItem['callnumber'] = $curRow['itemcallnumber'];
$curItem['volInfo'] = $curRow['enumchron'];
$curItem['copy'] = $curRow['itemcallnumber'];
$curItem['notes'] = $curRow['itemnotes'];
$curItem['dueDate'] = $curRow['onloan'];
//Figure out status based on all of the fields that make up the status
if ($curRow['damaged'] == 1) {
$curItem['status'] = "Damaged";
} else {
if ($curRow['itemlost'] != null) {
if ($curRow['itemlost'] == 'longoverdue') {
$curItem['status'] = "Long Overdue";
} elseif ($curRow['itemlost'] == 'missing') {
$curItem['status'] = "Missing";
} elseif ($curRow['itemlost'] == 'lost') {
$curItem['status'] = "Lost";
} elseif ($curRow['itemlost'] == 'trace') {
$curItem['status'] = "Trace";
}
} else {
if ($curRow['restricted'] == 1) {
$curItem['status'] = "Not For Loan";
} else {
if ($curRow['wthdrawn'] == 1) {
$curItem['status'] = "Withdrawn";
} else {
if ($curItem['dueDate'] == null) {
$curItem['status'] = "On Shelf";
} else {
$curItem['status'] = "Due {$curItem['dueDate']}";
}
}
}
}
}
$holdingsFromKoha[] = $curItem;
}
$results->close();
}
return $holdingsFromKoha;
}
示例9: multiexplode
<?php
$combinedVoteCount = $voteCount + $adminVote;
echo "Current likes: ";
echo $combinedVoteCount;
?>
<h2>Tags</h2>
<ul class="list-unstyled">
<?php
$tagsStmt = new mysqli_stmt($mysqli, "SELECT keywords FROM adventures WHERE id = ?");
$tagsStmt->bind_param("i", $adv_id);
$tagsStmt->execute();
$tagsResult = $tagsStmt->get_result();
$tagsTemp = $tagsResult->fetch_array();
$tagString = $tagsTemp['keywords'];
$tags = multiexplode(array(";", ","), $tagsTemp['keywords']);
foreach ($tags as $tag) {
echo "<li>" . $tag . "</li>";
}
?>
</ul>
</div>
</div>
<div class="row">
<div
class="col-md-5 col-md-offset-1 comments-section">
<h2>Comments <br></h2>
示例10: fetchAll
public function fetchAll()
{
return $this->statement->get_result()->fetch_all(MYSQLI_ASSOC);
}
示例11: execute
/**
* Execute the SQL statement.
*
* @return mixed A database cursor resource on success, boolean false on failure.
*
* @since 1.0
* @throws \RuntimeException
*/
public function execute()
{
$this->connect();
// Take a local copy so that we don't modify the original query and cause issues later
$sql = $this->replacePrefix((string) $this->sql);
if ($this->limit > 0 || $this->offset > 0) {
$sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
}
// Increment the query counter.
$this->count++;
// If debugging is enabled then let's log the query.
if ($this->debug) {
// Add the query to the object queue.
$this->log(Log\LogLevel::DEBUG, '{sql}', array('sql' => $sql, 'category' => 'databasequery', 'trace' => debug_backtrace()));
}
// Reset the error values.
$this->errorNum = 0;
$this->errorMsg = '';
// Execute the query.
$this->executed = false;
if ($this->prepared instanceof \mysqli_stmt) {
// Bind the variables:
if ($this->sql instanceof PreparableInterface) {
$bounded =& $this->sql->getBounded();
if (count($bounded)) {
$params = array();
$typeString = '';
foreach ($bounded as $key => $obj) {
// Add the type to the type string
$typeString .= $obj->dataType;
// And add the value as an additional param
$params[] = $obj->value;
}
// Make everything references for call_user_func_array()
$bindParams = array();
$bindParams[] =& $typeString;
for ($i = 0; $i < count($params); $i++) {
$bindParams[] =& $params[$i];
}
call_user_func_array(array($this->prepared, 'bind_param'), $bindParams);
}
}
$this->executed = $this->prepared->execute();
$this->cursor = $this->prepared->get_result();
// If the query was successful and we did not get a cursor, then set this to true (mimics mysql_query() return)
if ($this->executed && !$this->cursor) {
$this->cursor = true;
}
}
// If an error occurred handle it.
if (!$this->executed) {
$this->errorNum = (int) $this->connection->errno;
$this->errorMsg = (string) $this->connection->error;
// Check if the server was disconnected.
if (!$this->connected()) {
try {
// Attempt to reconnect.
$this->connection = null;
$this->connect();
} catch (ConnectionFailureException $e) {
$this->log(Log\LogLevel::ERROR, 'Database query failed (error #{code}): {message}; Failed query: {sql}', array('code' => $this->errorNum, 'message' => $this->errorMsg, 'sql' => $sql));
throw new ExecutionFailureException($sql, $this->errorMsg, $this->errorNum);
}
// Since we were able to reconnect, run the query again.
return $this->execute();
} else {
$this->log(Log\LogLevel::ERROR, 'Database query failed (error #{code}): {message}; Failed query: {sql}', array('code' => $this->errorNum, 'message' => $this->errorMsg, 'sql' => $sql));
throw new ExecutionFailureException($sql, $this->errorMsg, $this->errorNum);
}
}
return $this->cursor;
}
示例12: importFromMysqli
/**
* Import table headers and data from \mysqli_stmt
*
* @param \mysqli_stmt $stmt
*/
public function importFromMysqli(\mysqli_stmt $stmt)
{
$meta = $stmt->result_metadata();
$this->_header = array();
while (($column = $field = $meta->fetch_field()) !== false) {
$this->_header[] = $column->name;
}
$result = $stmt->get_result();
$this->_data = array();
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$this->_data[] = $row;
}
// if options is empty we want to regenerate defaults
if (count($this->_options) < 1) {
$this->setOptions();
}
$this->_executeFormats();
}
示例13: executeBasic
/**
* Executes a prepared statement. When using named parameters, use <code>executeQuery()</code> instead.
* @since 0.5.0
* @param mysqli_stmt $query The query to execute
* @param boolean $close Closes the query if set to <code>TRUE</code>.
* Set to <code>FALSE</code> to allow further parameter binds on this prepared statement.
* @return mysqli_result Query result set
*/
private function executeBasic(mysqli_stmt $query, $close = true)
{
$query->execute();
$result = $query->get_result();
$this->lastid = $query->insert_id;
$this->error = $query->error;
$this->errno = $query->errno;
$this->affected = $query->affected_rows;
$this->numrows = $query->num_rows;
if ($close) {
$query->close();
mysqli_close($this->con);
}
// error_log('result: ' . print_r($this, true));
return $result;
}