當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PDO::errorInfo方法代碼示例

本文整理匯總了PHP中PDO::errorInfo方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDO::errorInfo方法的具體用法?PHP PDO::errorInfo怎麽用?PHP PDO::errorInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PDO的用法示例。


在下文中一共展示了PDO::errorInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: update

 /**
  * @param PDO $link
  * @param string $user
  * @param string $field1
  * @param string $field2
  * @param string $lang
  * @param string $group
  * @param string $id1
  * @param string $id2
  * @param string $word
  * @param int $type
  */
 function update($link, $user, $field1, $field2, $lang, $group, $id1, $id2, $word, $type)
 {
     $sql = "SELECT associd FROM `associations` WHERE id1 = :id1 AND id2 = :id2 AND word = :word AND user = :user AND assigned_group = :group AND lang = :lang AND type = :type";
     $stmt = $link->prepare($sql);
     $stmt->bindValue(':id1', $id1, PDO::PARAM_STR);
     $stmt->bindValue(':id2', $id2, PDO::PARAM_STR);
     $stmt->bindValue(':word', $word, PDO::PARAM_STR);
     $stmt->bindValue(':type', $type, PDO::PARAM_INT);
     $stmt->bindValue(':user', $user, PDO::PARAM_STR);
     $stmt->bindValue(':group', $group, PDO::PARAM_STR);
     $stmt->bindValue(':lang', $lang, PDO::PARAM_STR);
     if ($stmt->execute() === false) {
         error_log(var_export($link->errorInfo(), true));
         die("Error performing database operation.");
     }
     if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $sql = "INSERT INTO `evaluations` ( associd , evaluator , vote , popvote ) values ( :associd , :user , :vote , :popvote )";
         $stmt = $link->prepare($sql);
         $stmt->bindValue(':associd', $row['associd'], PDO::PARAM_STR);
         $stmt->bindValue(':user', $_SESSION['user_array']['user'], PDO::PARAM_STR);
         $stmt->bindValue(':vote', $field1 === 'upvotes' ? 2 : ($field1 === 'neutralvotes' ? 1 : 0), PDO::PARAM_INT);
         $stmt->bindValue(':popvote', $field2 === 'popupvotes' ? 2 : ($field2 === 'popneutralvotes' ? 1 : 0), PDO::PARAM_INT);
         if ($stmt->execute() === false) {
             error_log(var_export($link->errorInfo(), true));
             die("Error performing database operation.");
         }
     }
 }
開發者ID:elcodedocle,項目名稱:synapp,代碼行數:40,代碼來源:put_evaluation.php

示例2: do_query

 /**
  * Prepare and execute a query.
  *
  * If the query fails, output a diagnostic message
  * @param string $query
  *   Query to run
  * @return bool
  */
 public function do_query($query)
 {
     // echo "do_query($query)\n";
     // $stmt = $this->pdo->query( $query, PDO::FETCH_ASSOC );
     // echo "PDO returned";
     // var_dump($stmt);
     $string = preg_replace("/^#[^\n]*\$/m", "\n", $query);
     $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
     $queries = preg_split('/;\\s*$/m', $string);
     foreach ($queries as $query) {
         $query = trim($query);
         if (!empty($query)) {
             $result = $this->pdo->query($query);
             if ($this->pdo->errorCode() == 0) {
                 continue;
             } else {
                 var_dump($result);
                 var_dump($this->pdo->errorInfo());
                 // die( "Cannot execute $query: " . $this->pdo->errorInfo() );
             }
         }
     }
     /*******
      * if ( $this->pdo->errorCode() == 0 ) {
      * //echo "returning the PDOStmt\n";
      * return $stmt;
      * }
      *
      * //  operation failed, so output description of where and why
      * $errorInfo = $this->pdo->errorInfo();
      * echo "Oops, can't do query:\n    {$query}\n    in "
      * . basename( __FILE__) . " line " . __LINE__.":\n    "
      * . $errorInfo[0] . ": " . $errorInfo[2] . "\n    Call stack:\n";
      * $backtrace = debug_backtrace();
      * $dir_name  = dirname( __FILE__ );
      * $cwd_len   = strlen( $dir_name ) + 1;
      * foreach ($backtrace as $frame ) {
      * echo "      ";
      * if ( array_key_exists( 'class', $frame ) ) {
      * echo " class {$frame['class']}";
      * if ( array_key_exists( 'function', $frame ) ) {
      * echo " method {$frame['function']}";
      * }
      * }
      * else {
      * if ( array_key_exists( 'function', $frame ) ) {
      * echo " function {$frame['function']}";
      * }
      * }
      * if ( array_key_exists( 'file', $frame ) ) {
      * echo " file ". substr( $frame['file'], $cwd_len );
      * }
      * if ( array_key_exists( 'line', $frame ) ) {
      * echo " line {$frame['line']}";
      * }
      * echo "\n";
      * }
      ******/
     return TRUE;
 }
開發者ID:FundingWorks,項目名稱:civicrm-core,代碼行數:68,代碼來源:Utils.php

示例3: query

 /**
  * {@inheritdoc}
  */
 public function query($query, $resultsetType = Resultset::TYPE_ARRAY)
 {
     try {
         //$query = "select * from product";
         $stmt = $this->resource->prepare($query);
         if ($stmt === false) {
             $error = $this->resource->errorInfo();
             throw new Exception\InvalidArgumentException($error[2]);
         }
         if (!$stmt->execute()) {
             throw new Exception\InvalidArgumentException('Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')');
         }
         $results = new Resultset($resultsetType);
         if ($stmt->columnCount() > 0) {
             while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                 $results->append($row);
             }
         }
         $stmt->closeCursor();
     } catch (Exception\InvalidArgumentException $e) {
         throw $e;
     } catch (\Exception $e) {
         $eclass = get_class($e);
         $msg = "GenericPdo '{$eclass}' : {$e->getMessage()} [{$query}]";
         throw new Exception\InvalidArgumentException($msg);
     }
     return $results;
 }
開發者ID:belgattitude,項目名稱:soluble-dbwrapper,代碼行數:31,代碼來源:GenericPdo.php

示例4: _error_handler

 private function _error_handler($errtext, $errline)
 {
     $err = sprintf('%s on line %d.', $errtext, $errline);
     if (defined('DEBUG') && DEBUG) {
         $err .= sprintf(PHP_EOL . "Description: %s", print_r($this->con->errorInfo(), true));
     }
     throw new RuntimeException($err);
 }
開發者ID:Kennyl,項目名稱:pixmicat,代碼行數:8,代碼來源:pio.sqlite3.php

示例5: get_error_message

 /**
  * Get the latest error message from the DB driver
  *
  * @return string
  */
 public function get_error_message()
 {
     $error = $this->dbh->errorInfo();
     if (isset($error[2])) {
         return $error[2];
     }
     return '';
 }
開發者ID:mpeshev,項目名稱:wp-db-driver,代碼行數:13,代碼來源:pdo_mysql.php

示例6: initDb

 private function initDb()
 {
     $this->pdo = new \PDO($this->dns, $this->user, $this->pass, $this->options);
     if ($this->pdo == false) {
         throw new \Exception(var_export($this->pdo->errorInfo(), true));
     }
     $this->optionsChanged = false;
 }
開發者ID:dreamblazenet,項目名稱:crazydatamapper,代碼行數:8,代碼來源:PdoDatabaseConnection.php

示例7: DoLastError

 public function DoLastError()
 {
     if ($this->connection) {
         $pdoErrorInfo = $this->connection->errorInfo();
         return $pdoErrorInfo[2];
     } else {
         return $this->connectionError;
     }
 }
開發者ID:blakeHelm,項目名稱:BallotPath,代碼行數:9,代碼來源:pdo_engine.php

示例8: loadFixture

 /**
  * @param string $fixture
  *
  * @throws \InvalidArgumentException
  */
 public function loadFixture($fixture)
 {
     if (!is_file(__DIR__ . "/fixtures/{$fixture}.sql")) {
         throw new \InvalidArgumentException("The asked fixture file {$fixture}.sql does not exists");
     }
     $success = $this->getConnection()->exec(file_get_contents(__DIR__ . "/fixtures/{$fixture}.sql"));
     if ($success === false) {
         $this->fail("Error with {$fixture} fixtures : {$this->connection->errorInfo()[2]}");
     }
 }
開發者ID:poisoned-apple,項目名稱:8thWonderland,代碼行數:15,代碼來源:WonderlandTestCase.php

示例9: error

 /**
  * Generate PDO error
  *
  * @param string $sql
  * @param \PDOStatement $statement
  * @return \PDOException
  */
 protected function error($sql, \PDOStatement $statement = null)
 {
     $error = $this->pdo->errorInfo();
     if (!$error[1] and $statement) {
         $error = $statement->errorInfo();
         $statement->closeCursor();
         unset($statement);
     }
     $code = is_int($error[0]) ? $error[0] : null;
     return new \PDOException('[' . $error[0] . '] ' . $error[2] . ', in query (' . $sql . ')', $code);
 }
開發者ID:colorium,項目名稱:orm,代碼行數:18,代碼來源:SafePDO.php

示例10: getMembers

 /**
  * @return Member[]
  */
 public function getMembers()
 {
     $statement = $this->pdo->query('SELECT * FROM members');
     if (false === $statement) {
         throw new \PDOException(join("\n", $this->pdo->errorInfo()), $this->pdo->errorCode());
     }
     $members = [];
     while ($row = $statement->fetch(\PDO::FETCH_OBJ)) {
         $members[] = $this->rowToMember($row);
     }
     return $members;
 }
開發者ID:belanur,項目名稱:docker-example,代碼行數:15,代碼來源:MemberReader.php

示例11: run

 public function run(SqlFile $file)
 {
     $statement = $this->pdo->prepare($file->getContents());
     try {
         $result = $statement->execute();
         if ($result === false) {
             throw new \Exception("Query Returned " . var_export($this->pdo->errorInfo(), true));
         }
     } catch (\Exception $e) {
         throw new MigrationException("Running SQL File " . $file->getFile()->getPathname() . " failed.", $e);
     } finally {
         $statement->closeCursor();
     }
 }
開發者ID:newcron,項目名稱:dbmigration,代碼行數:14,代碼來源:RunMigration.php

示例12: executePdoQuery

 /**
  * Internal function to execute PDO queries when the 
  * query option is set to a PDO object
  * @param  string $query      The SQL query to execute
  * @param  array $parameters  Parameters to bind to the query
  * @return array             
  */
 function executePdoQuery($query, $parameters)
 {
     $stmt = $this->dbh->prepare($query);
     if (!$stmt) {
         echo "Error in preparing query: " . $this->dbh->errorCode() . " " . htmlentities(print_r($this->dbh->errorInfo(), true)) . " " . htmlentities($query);
         exit;
     }
     $res = $stmt->execute($parameters);
     if (!$res) {
         echo "Error in executing query: " . $stmt->errorCode() . " " . htmlentities(print_r($stmt->errorInfo(), true)) . " " . htmlentities($query);
         exit;
     }
     return $stmt->fetchAll(\PDO::FETCH_ASSOC);
 }
開發者ID:dlid,項目名稱:cdbyuml,代碼行數:21,代碼來源:COptions.php

示例13: open_db

function open_db()
{
    // Try to open the db itself.  If that fails, try to create it.
    $dbFile = SUPPORT_DIR . DIRECTORY_SEPARATOR . "jobs.sqlite";
    $pdo = new PDO("sqlite:{$dbFile}", null, null);
    if (!$pdo) {
        throw new DbException($pdo->errorInfo(), "Error opening (or creating) " . $dbFile);
    }
    $stmt = 'CREATE TABLE IF NOT EXISTS ' . TABLE_NAME . ' (jobId TEXT, username TEXT, filename TEXT, when_added INTEGER, PRIMARY KEY (jobId))';
    // SQLite doesn't have a specific date type.  We're using integer seconds (Unix time)
    if ($pdo->exec($stmt) === false) {
        throw new DbException($pdo->errorInfo(), 'Error creating ' . TABLE_NAME . ' table');
    }
    return $pdo;
}
開發者ID:neutrons,項目名稱:MWS-Front-End,代碼行數:15,代碼來源:db_functions.php

示例14: query

 /**
  * 執行一條sql語句
  * 返回數組或者bool
  *
  * @param $sql
  * @return array|bool
  */
 public function query($sql)
 {
     $dbh = $this->dbh;
     $this->_beforeQuery($sql);
     $ps = $dbh->query($sql);
     $error_info = $this->dbh->errorInfo();
     if ($error_info[2] != null) {
         throw new Exception("Excute Sql Error: " . $error_info[2]);
     }
     if (is_bool($ps)) {
         return $ps;
     }
     $obj = $ps->fetchAll(PDO::FETCH_ASSOC);
     return $obj;
 }
開發者ID:princehaku,項目名稱:flowphp,代碼行數:22,代碼來源:Basic.php

示例15: execute

 /**
  * @param string $cmd Sql SAFE query to execute.
  * @param array $bind Array of parameters to bind.
  * @throws \PDOException
  * @return \PDOStatement
  */
 public function execute($cmd, array $bind = [])
 {
     if (is_null($this->pdo)) {
         $this->openConnection();
     }
     $statement = $this->pdo->prepare($cmd);
     if (!$statement) {
         throw MySqlException::create($this->pdo->errorInfo());
     }
     $result = $statement->execute($bind);
     if (!$result) {
         throw MySqlException::create($statement->errorInfo());
     }
     return $statement;
 }
開發者ID:oktopost,項目名稱:squid,代碼行數:21,代碼來源:MySqlConnection.php


注:本文中的PDO::errorInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。