本文整理汇总了PHP中mysqli_stmt::reset方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt::reset方法的具体用法?PHP mysqli_stmt::reset怎么用?PHP mysqli_stmt::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli_stmt
的用法示例。
在下文中一共展示了mysqli_stmt::reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* 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;
}
示例2: executeAndFetch
function executeAndFetch($className = self::DEFAULT_CLASS_NAME, $type = self::RESULT_OBJECT, array $iteratorMap = null)
{
try {
$this->execute();
} catch (\Exception $ex) {
throw $ex;
}
switch ($type) {
case self::RESULT_OBJECT:
$objectBuilder = $className != self::DEFAULT_CLASS_NAME ? new ObjectBuilderUtil($className) : null;
return $this->fetchObject($className, $objectBuilder, $iteratorMap);
case self::RESULT_ARRAY:
return $this->fetchArray($iteratorMap);
default:
throw new \InvalidArgumentException('Invalid Return Type');
}
$this->stmt->free_result();
if (!$this->reusable) {
$this->stmt->close();
unset($this->stmt);
} else {
$this->stmt->reset();
}
}
示例3: execute
/**
* Executes the prepared statement. If the prepared statement included parameter
* markers, you must either:
* <ul>
* <li>call {@link \TYPO3\CMS\Core\Database\PreparedStatement::bindParam()} to bind PHP variables
* to the parameter markers: bound variables pass their value as input</li>
* <li>or pass an array of input-only parameter values</li>
* </ul>
*
* $input_parameters behave as in {@link \TYPO3\CMS\Core\Database\PreparedStatement::bindParams()}
* and work for both named parameters and question mark parameters.
*
* Example 1:
* <code>
* $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = ? AND bug_status = ?');
* $statement->execute(array('goofy', 'FIXED'));
* </code>
*
* Example 2:
* <code>
* $statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'bugs', 'reported_by = :nickname AND bug_status = :status');
* $statement->execute(array(':nickname' => 'goofy', ':status' => 'FIXED'));
* </code>
*
* @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. The PHP type of each array value will be used to decide which PARAM_* type to use (int, string, boolean, NULL), so make sure your variables are properly casted, if needed.
* @return bool Returns TRUE on success or FALSE on failure.
* @throws \InvalidArgumentException
* @api
*/
public function execute(array $input_parameters = array())
{
$parameterValues = $this->parameters;
if (!empty($input_parameters)) {
$parameterValues = array();
foreach ($input_parameters as $key => $value) {
$parameterValues[$key] = array('value' => $value, 'type' => $this->guessValueType($value));
}
}
if ($this->statement !== NULL) {
// The statement has already been executed, we try to reset it
// for current run but will set it to NULL if it fails for some
// reason, just as if it were the first run
if (!@$this->statement->reset()) {
$this->statement = NULL;
}
}
if ($this->statement === NULL) {
// The statement has never been executed so we prepare it and
// store it for further reuse
$query = $this->query;
$precompiledQueryParts = $this->precompiledQueryParts;
$this->convertNamedPlaceholdersToQuestionMarks($query, $parameterValues, $precompiledQueryParts);
if (!empty($precompiledQueryParts)) {
$query = implode('', $precompiledQueryParts['queryParts']);
}
$this->statement = $GLOBALS['TYPO3_DB']->prepare_PREPAREDquery($query, $precompiledQueryParts);
if ($this->statement === NULL) {
return FALSE;
}
}
$combinedTypes = '';
$values = array();
foreach ($parameterValues as $parameterValue) {
switch ($parameterValue['type']) {
case self::PARAM_NULL:
$type = 's';
$value = NULL;
break;
case self::PARAM_INT:
$type = 'i';
$value = (int) $parameterValue['value'];
break;
case self::PARAM_STR:
$type = 's';
$value = $parameterValue['value'];
break;
case self::PARAM_BOOL:
$type = 'i';
$value = $parameterValue['value'] ? 1 : 0;
break;
default:
throw new \InvalidArgumentException(sprintf('Unknown type %s used for parameter %s.', $parameterValue['type'], $key), 1281859196);
}
$combinedTypes .= $type;
$values[] = $value;
}
// ->bind_param requires second up to last arguments as references
if (!empty($combinedTypes)) {
$bindParamArguments = array();
$bindParamArguments[] = $combinedTypes;
$numberOfExtraParamArguments = count($values);
for ($i = 0; $i < $numberOfExtraParamArguments; $i++) {
$bindParamArguments[] =& $values[$i];
}
call_user_func_array(array($this->statement, 'bind_param'), $bindParamArguments);
}
$success = $this->statement->execute();
// Store result
if (!$success || $this->statement->store_result() === FALSE) {
return FALSE;
//.........这里部分代码省略.........