本文整理汇总了PHP中PDOStatement::errorCode方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::errorCode方法的具体用法?PHP PDOStatement::errorCode怎么用?PHP PDOStatement::errorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOStatement
的用法示例。
在下文中一共展示了PDOStatement::errorCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute($input_parameters = NULL)
{
if (APF::get_instance()->is_debug_enabled()) {
APF::get_instance()->debug(__CLASS__ . '[' . $this->pdo->config['dsn'] . '|' . $this->pdo->get_name() . ']' . "->execute: " . $this->queryString);
}
$logger = APF::get_instance()->get_logger();
$logger->debug(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
APF::get_instance()->pf_benchmark_inc_begin('dbtime');
$start = microtime(true);
$ret = parent::execute($input_parameters);
$end = microtime(true);
APF::get_instance()->pf_benchmark_inc_end('dbtime');
//add by hexin for record SQL execute time
APF::get_instance()->pf_benchmark("sql_time", array($this->i => $end - $start));
if (!$ret) {
$error_info = parent::errorInfo();
$logger->error(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
$_error_info = preg_replace("#[\r\n \t]+#", ' ', print_r($error_info, true));
$logger->error(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $_error_info);
if (parent::errorCode() !== '00000') {
trigger_error($this->queryString . ' | ' . join(' | ', $error_info), E_USER_ERROR);
}
}
return $ret;
}
示例2: errorCode
public function errorCode()
{
if ($this->_statement instanceof \PDOStatement) {
return $this->_statement->errorCode();
}
return null;
}
示例3: getErrorNumber
/**
* Returns the number of the last error.
*
* @return integer
*/
public function getErrorNumber()
{
if ($this->pdoStatement !== null) {
return $this->pdoStatement->errorCode();
}
return 0;
}
示例4: errorCode
/**
* Renvoi le code de la dernière erreur
*
*/
public function errorCode()
{
if (is_object($this->stmt)) {
$code = $this->stmt->errorCode();
return PDO::ERR_NONE == $code ? null : $code;
}
}
示例5: execute
public function execute($input_parameters = NULL)
{
if (APF::get_instance()->is_debug_enabled()) {
APF::get_instance()->debug(__CLASS__ . '[' . $this->pdo->config['dsn'] . '|' . $this->pdo->get_name() . ']' . "->execute: " . $this->queryString);
}
$logger = APF::get_instance()->get_logger();
$logger->debug(__CLASS__, '[' . $this->pdo->get_name() . ']->execute: ', $this->queryString);
APF::get_instance()->pf_benchmark_inc_begin('dbtime');
$start = microtime(true);
$ret = parent::execute($input_parameters);
$end = microtime(true);
APF::get_instance()->pf_benchmark_inc_end('dbtime');
//add by hexin for record SQL execute time
APF::get_instance()->pf_benchmark("sql_time", array($this->i => $end - $start));
// 按照惯用格式记录sql执行时间和占用内存
// added by htlv
$tmp_time = $end - $start;
$tmp_mem = memory_get_usage();
apf_require_class('APF_Performance');
APF::get_instance()->pf_benchmark("sql_time_af", array($this->i => array('sql' => $this->_sql, APF_Performance::MESSAGE_TIME => $tmp_time, APF_Performance::MESSAGE_MEMORY => $tmp_mem)));
if (!$ret) {
$error_info = parent::errorInfo();
/**
* remove duplicated error log
$logger->error(__CLASS__, '['. $this->pdo->get_name() .']->execute: ', $this->queryString);
$_error_info = preg_replace("#[\r\n \t]+#",' ',print_r($error_info,true));
$logger->error(__CLASS__, '['. $this->pdo->get_name() .']->execute: ', $_error_info);
*/
if (parent::errorCode() !== '00000') {
throw new APF_Exception_SqlException($this->pdo->get_name() . ' | ' . $this->pdo->config['dsn'] . ' | ' . $this->queryString . ' | ' . join(' | ', $error_info), parent::errorCode());
}
}
return $ret;
}
示例6: __construct
public function __construct($message, PDOStatement $statement)
{
$infos = array();
foreach ($statement->errorInfo() as $key => $info) {
$infos[] = $key . ': ' . $info;
}
parent::__construct($message . '. (ERRNO ' . $statement->errorCode() . ') ' . implode('<br />', $infos));
}
示例7: errorCode
/**
* Returns the last error code generated by the wrapped PDO object. Please
* the PDOStatement::errorCode method for prepared statements.
*
* @access public
* @author Jerome Bogaerts, <jerome@taotesting.com>
* @return string
*/
private function errorCode()
{
if ($this->preparedExec == false) {
$returnValue = $this->dbConnector->errorCode();
} else {
$returnValue = $this->lastPreparedExecStatement->errorCode();
}
return (string) $returnValue;
}
示例8: errorCode
/**
* Retrieves the error code, if any, associated with the last operation on
* the statement handle.
*
* @return string error code.
* @throws Zend_Db_Statement_Exception
*/
public function errorCode()
{
try {
return $this->_stmt->errorCode();
} catch (PDOException $e) {
require_once 'Zend/Db/Statement/Exception.php';
throw new Zend_Db_Statement_Exception($e->getMessage());
}
}
示例9: query
/**
* Permet d'exécuter une requête.
*
* Aucun résultat n'est renvoyé par cette fonction. Elle doit être utilisé pour effectuer
* des insertions, des updates... Elle est de même utilisée par les
* autres fonction de la classe comme queryRow() et queryTab().
*
* @param string $query chaine SQL
* @param mixed $param variables bind de type array(":bind"=>"value")
* @return void
*/
public function query($query, $param = array()) {
global $sysNbQuery;
// execution de la requête
$this->query = (isset($_SERVER['HOSTNAME']) ? '/*SIG'.$_SERVER['HOSTNAME'].'SIG*/ ' : '').$query;
$this->param = $param;
$this->errorParams = array();
$this->errorParams['Request'] = $query;
$this->errorParams['Bind'] = $param;
$this->id->setAttribute(PDO::ATTR_AUTOCOMMIT, $this->getCommitMode());
$this->id->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$sysNbQuery = (!isset($sysNbQuery) || $sysNbQuery<=0) ? 1 : $sysNbQuery+1;
// Prepare de la requête
$queryMD5 = md5($query);
if(!isset($this->aPrepare[$queryMD5])) {
$this->lPrepare = $this->id->prepare($this->query);
$this->aPrepare[$queryMD5] = $this->lPrepare;
} else {
$this->lPrepare = $this->aPrepare[$queryMD5];
}
if ($this->lPrepare!==false) {
// Bind des paramètres
if($param) {
foreach($param as $key => $val) {
if (strpos($query, $key) !== false) {
if($param[$key]===null) $this->lPrepare->bindParam(trim($key), $param[$key], PDO::PARAM_NULL);
else $this->lPrepare->bindParam(trim($key), $param[$key]);
}
}
}
// Execution de la requête
$rs = $this->lPrepare->execute();
if ($this->lPrepare->errorCode() != PDO::ERR_NONE) {
$this->errorParams['errorInfo'] = $this->lPrepare->errorInfo();
//echo'<xmp>Erreur execute() de PDO : '.$this->errorParams['errorInfo'][2];print_r($query);echo'</xmp>';
//Génération d'une DataBaseException
//throw new DataBaseException("Erreur execute() de PDO",$error[2],$this->errorParams);
}
return $rs;
}else{
$this->errorParams['errorInfo'] = $this->lPrepare->errorInfo();
//echo'<xmp>Erreur prepare() de PDO : '.$this->errorParams['errorInfo'][2];print_r($query);echo'</xmp>';
//DatabaseManager::log($this, true);
//throw new DataBaseException("Erreur prepare() de PDO",$this->id->errorInfo(),$this->errorParams);
}
return false;
}
示例10: isFailure
/**
* @param PDOStatement|boolean $sth
* @param mixed $result
* @return boolean TRUE if $result indicates failure, FALSE otherwise
*/
private function isFailure($sth, $result)
{
if ($result === false) {
$error = $sth->errorInfo();
$this->lastError = 'DB ERROR: [' . $sth->errorCode() . '] ' . $error[2];
error_log($this->lastError);
return true;
}
return false;
}
示例11: __construct
/**
* Constructor.
*
* @param \PDOStatement $pdoStatement
* @param mixed $mapFunction
* @param int $fetchStyle Controls how the row will be returned
*
* @throws \Quaver\Core\QException
*/
public function __construct($pdoStatement, $mapFunction, $fetchStyle = \PDO::ATTR_DEFAULT_FETCH_MODE)
{
if ($pdoStatement->errorCode() != 0) {
throw new QException('PDO statement with errors');
}
$this->stm = $pdoStatement;
$this->mapFunction = $mapFunction;
$this->fetchStyle = $fetchStyle;
$this->cur = 0;
$this->count = $pdoStatement->rowCount();
$this->next();
}
示例12: execute
/**
* Executes the statement.
*
* @return boolean
* @throws DBQueryException
*/
public function execute()
{
$start = microtime(true);
$this->query->execute();
$end = microtime(true);
$sql = (string) $this->query->queryString;
$error_id = (int) $this->query->errorCode();
if ($this->callback) {
$time = ($end - $start) * 1000;
call_user_func_array($this->callback, array($sql, $time));
}
if ($error_id) {
$error = $this->query->errorInfo();
$message = "Database query error: ({$error[0]}/{$error[1]}) {$error[2]} in query [{$sql}]";
throw new DBQueryException($message, E_USER_WARNING);
return false;
}
$this->key = 0;
$this->count = $this->query->rowCount();
$this->current = $this->query->fetch();
}
示例13: execute
public function execute($inputParameters = array())
{
$ret = parent::execute($inputParameters);
Debugger::getInstance()->debug('SQL:' . $this->queryString . ';params:' . var_export($inputParameters, true));
if (!$ret) {
$error_info = parent::errorInfo();
if (parent::errorCode() != '00000') {
// 执行成功时返回五个零
LoggerFactory::getLogger()->error('PDO executed failed,errors:' . var_export($error_info, true));
trigger_error($this->queryString, E_USER_ERROR);
}
}
return $ret;
}
示例14: rewind
/**
*
* @see Iterator::rewind()
*/
public function rewind()
{
//Dirty hack because rewind() is called before entering the loop
//and on object creation we already have query executed
if ($this->_needsRefresh) {
$this->_refresh();
} else {
$this->_needsRefresh = true;
}
$this->_currentRowObj = $this->_statement->fetchObject('\\phpSweetPDO\\RecordsetRow');
if ($this->_statement->errorCode() !== '00000') {
throw new DbException($this->_statement->errorInfo(), $this->_statement->queryString);
}
}
示例15: execute
/**
* Executes the query that was previously passed to the constructor.
*
* @param mixed $arg Query arguments to escape and insert at ? placeholders in $query
* @param mixed ... Additional arguments
**/
public function execute()
{
// We can't very well perform a query wtihout an active connection.
if (!is_object($this->dbh)) {
$this->db->error('Lost connection to database.');
return;
}
// end if
// Finish any previous statements
$this->finish();
// We need to pre-process the arguments for literals and bytefields. We
// can't safely pass them into the PDO placeholder system, so we'll
// have to stick them into the query at the right places before then.
$args = Database::smart_args(func_get_args());
list($query, $nargs, $nargn) = $this->reprocess_query($args);
if (!$query) {
return;
}
$this->last_query = $this->unprocess_query($query, $nargn);
// Wrap the actual query execution in a bit of benchmarking.
$before = microtime(true);
$this->last_exception = null;
try {
// We will always create a new statement. The possibility of missing
// & pre-replaced placeholders breaks our ability to work with actual
// prepared statements. Additionally, PDO tends to break easily when
// working on prepared statements that return multiple result sets
// combined with multiple concurrent statement handles. See the
// comments on the PDOStatement::closeCursor() manual page.
// Skip preparing the query if there are no args in the query.
if ($nargn == 0) {
$this->sh = $this->dbh->query($this->last_query);
} else {
$this->sh = $this->dbh->prepare($this->last_query);
$this->sh->execute($nargs);
}
} catch (PDOException $e) {
$this->last_exception = $e;
$this->db->error('SQL Error:');
return false;
}
// end try
$after = microtime(true);
$this->db->mysql_time += $after - $before;
// The other adapters handle these here. Fun times.
// Problem 1:
// PDO does not provide a clear way to get the last inserted primary key.
// There's PDO::lastInsertId(), but it's poorly supported and sometimes
// requires extra arguments be passed. There's undoubtedly a better
// way to deal with this than to not deal with it.
$this->insert_id = null;
// Problem 2:
// PDOStatement::rowCount()'s manual page says:
// "If the last SQL statement executed by the associated PDOStatement
// was a SELECT statement, some databases may return the number of
// rows returned by that statement. However, this behaviour is not
// guaranteed for all databases and should not be relied on for
// portable applications."
// So, unlike the other adapters, there's no separate call for getting
// the number of returned rows vs the number of affected rows.
// We'll just use it here and hope it works and that calling code doesn't
// care too much.
// Overall, PDO kind of sucks for this kind of thing.
$this->affected_rows = $this->sh->rowCount();
$this->num_rows = $this->sh->rowCount();
// PDO has no way to check warnings. We won't try.
$this->warnings = array();
// But we do have errors, though this *should* never be called thanks to the
// exception catching above.
$last_notice = $this->sh->errorCode();
if ($last_notice == '00000' || empty($last_notice)) {
$last_notice = null;
}
if ($last_notice) {
$this->db->error('SQL Error:');
return false;
}
return true;
}