本文整理匯總了PHP中Fisharebest\Webtrees\Database::logQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::logQuery方法的具體用法?PHP Database::logQuery怎麽用?PHP Database::logQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Fisharebest\Webtrees\Database
的用法示例。
在下文中一共展示了Database::logQuery方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* Execute a query
*
* @param array $bind_variables
*
* @throws \Exception
*
* @return Statement
*/
public function execute($bind_variables = array())
{
if ($this->executed) {
throw new \Exception('Statement::execute() called twice.');
}
// Parameters may be either named (e.g. :foo) or positional (e.g. ?).
// Named parameters may take any type. Positional parameters are always strings.
// Queries should use one format or the other.
foreach ($bind_variables as $key => $bind_variable) {
if (is_numeric($key)) {
// Positional parameters are numeric (starting at 1)
$key = 1 + $key;
} else {
// Named parameters are prefixed with a colon
$key = ':' . $key;
}
switch (gettype($bind_variable)) {
case 'NULL':
$this->pdo_statement->bindValue($key, $bind_variable, PDO::PARAM_NULL);
break;
case 'boolean':
$this->pdo_statement->bindValue($key, (int) $bind_variable, PDO::PARAM_INT);
break;
case 'integer':
$this->pdo_statement->bindValue($key, $bind_variable, PDO::PARAM_INT);
break;
default:
$this->pdo_statement->bindValue($key, $bind_variable, PDO::PARAM_STR);
break;
}
}
$start = microtime(true);
$this->pdo_statement->execute();
$end = microtime(true);
// If it was a SELECT statement, we cannot run it again.
$this->executed = strpos($this->pdo_statement->queryString, 'SELECT') === 0;
Database::logQuery($this->pdo_statement->queryString, $this->pdo_statement->rowCount(), $end - $start, $bind_variables);
return $this;
}