当前位置: 首页>>代码示例>>PHP>>正文


PHP PDOStatement::errorCode方法代码示例

本文整理汇总了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;
 }
开发者ID:rh20083907,项目名称:ipublish,代码行数:25,代码来源:PDOStatement.php

示例2: errorCode

 public function errorCode()
 {
     if ($this->_statement instanceof \PDOStatement) {
         return $this->_statement->errorCode();
     }
     return null;
 }
开发者ID:rtshome,项目名称:pgbabylon,代码行数:7,代码来源:PDOStatement.php

示例3: getErrorNumber

 /**
  * Returns the number of the last error.
  * 
  * @return integer
  */
 public function getErrorNumber()
 {
     if ($this->pdoStatement !== null) {
         return $this->pdoStatement->errorCode();
     }
     return 0;
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:12,代码来源:PreparedStatement.class.php

示例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;
     }
 }
开发者ID:Qwaseur,项目名称:SACoche,代码行数:11,代码来源:DB_driver_PDO.class.php

示例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;
 }
开发者ID:emilymwang8,项目名称:cms,代码行数:34,代码来源:PDOStatement.php

示例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));
 }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:8,代码来源:PDOQuerierException.class.php

示例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;
 }
开发者ID:nagyist,项目名称:generis,代码行数:17,代码来源:class.Driver.php

示例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());
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:16,代码来源:Pdo.php

示例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;
	}
开发者ID:rhertzog,项目名称:lcs,代码行数:67,代码来源:DAO.class.php

示例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;
 }
开发者ID:enygma,项目名称:modler,代码行数:15,代码来源:Mysql.php

示例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();
 }
开发者ID:millolab,项目名称:quaver-core,代码行数:21,代码来源:NoRewindIterator.php

示例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();
 }
开发者ID:Acidburn0zzz,项目名称:OEM,代码行数:27,代码来源:DBResult.php

示例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;
 }
开发者ID:zhxia,项目名称:nspf,代码行数:14,代码来源:Statement.php

示例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);
     }
 }
开发者ID:neevan1e,项目名称:Done,代码行数:18,代码来源:db.recordset.class.php

示例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;
 }
开发者ID:qbdsoft,项目名称:Query-Digest-UI,代码行数:85,代码来源:pdo.php


注:本文中的PDOStatement::errorCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。