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


PHP PDO::errorCode方法代码示例

本文整理汇总了PHP中PDO::errorCode方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::errorCode方法的具体用法?PHP PDO::errorCode怎么用?PHP PDO::errorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PDO的用法示例。


在下文中一共展示了PDO::errorCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: testMySQL

    /**
     * Tests MySQL connection
     *
     * @return void
     */
    public function testMySQL()
    {
        try {
            $pdo = new PDO(
                "mysql:host=" . TESTSUITE_SERVER . ";dbname=" . TESTSUITE_DATABASE,
                TESTSUITE_USER,
                TESTSUITE_PASSWORD
            );
            $this->assertNull(
                $pdo->errorCode(),
                "Error when trying to connect to database"
            );

            //$pdo->beginTransaction();
            $test = $pdo->exec("SHOW TABLES;");
            //$pdo->commit();
            $this->assertEquals(
                0,
                $pdo->errorCode(),
                'Error trying to show tables for database'
            );
        }
        catch (Exception $e) {
            $this->fail("Error: ".$e->getMessage());
        }

        // Check id MySQL server is 5 version
        preg_match(
            "/^(\d+)?\.(\d+)?\.(\*|\d+)/",
            $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")),
            $version_parts
        );
        $this->assertEquals(5, $version_parts[1]);
    }
开发者ID:nhodges,项目名称:phpmyadmin,代码行数:39,代码来源:Environment_test.php

示例3: __construct

 public function __construct(PDO $dbh)
 {
     if ($dbh->errorCode() !== NULL) {
         echo "database handle invalid, error code " . $dbh->errorCode();
         return;
     }
     $this->dbh = $dbh;
 }
开发者ID:Gelio,项目名称:vote-app,代码行数:8,代码来源:database.php

示例4: 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

示例5: checkDatabase

 public function checkDatabase()
 {
     try {
         $this->pdo->query("select 1 from `{$this->tableName}` limit 1");
         if ($this->pdo->errorCode() == '00000') {
             return;
         }
         //return;
     } catch (\Exception $ex) {
     }
     $this->pdo->exec("DROP TABLE IF EXISTS `{$this->tableName}`");
     $this->pdo->exec("\nCREATE TABLE IF NOT EXISTS `{$this->tableName}` (\n  `shopname` varchar(255) DEFAULT NULL,\n  `scope` varchar(255) DEFAULT NULL,\n  `nonce` varchar(255) DEFAULT NULL,\n  `token` varchar(255) DEFAULT NULL,\n  `last_modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`shopname`,`scope`)\n)");
 }
开发者ID:cdyweb,项目名称:shopify-client,代码行数:13,代码来源:PDOTokenStorage.php

示例6: testMySQL

 /**
  * Tests MySQL connection
  *
  * @return void
  */
 public function testMySQL()
 {
     try {
         $pdo = new PDO("mysql:host=" . $GLOBALS['TESTSUITE_SERVER'], $GLOBALS['TESTSUITE_USER'], $GLOBALS['TESTSUITE_PASSWORD']);
         $this->assertNull($pdo->errorCode(), "Error when trying to connect to database");
         $pdo->exec("SHOW DATABASES;");
         $this->assertEquals(0, $pdo->errorCode(), 'Error trying to show tables for database');
     } catch (Exception $e) {
         $this->markTestSkipped("Error: " . $e->getMessage());
     }
     // Check id MySQL server is 5 version
     preg_match("/^(\\d+)?\\.(\\d+)?\\.(\\*|\\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts);
     $this->assertEquals(5, $version_parts[1]);
 }
开发者ID:itgsod-philip-skalander,项目名称:phpmyadmin,代码行数:19,代码来源:Environment_test.php

示例7: 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

示例8: errorCode

 public function errorCode()
 {
     if ($this->connected) {
         return parent::errorCode();
     }
     return 0;
 }
开发者ID:BackupTheBerlios,项目名称:openpb-svn,代码行数:7,代码来源:opd.class.php

示例9: getErrorNumber

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

示例10: execute

 /**
  * Executes a SQL statement
  *
  * @param mixed $po_caller object representation of the calling class, usually Db()
  * @param PDOStatement $opo_statement
  * @param string $ps_sql SQL statement
  * @param array $pa_values array of placeholder replacements
  * @return bool|DbResult
  */
 public function execute($po_caller, $opo_statement, $ps_sql, $pa_values)
 {
     if (!$ps_sql) {
         $po_caller->postError(240, _t("Query is empty"), "Db->pdo_mysql->execute()");
         return false;
     }
     if (!$opo_statement instanceof PDOStatement) {
         $po_caller->postError(250, _t("Invalid prepared statement"), "Db->pdo_mysql->execute()");
         return false;
     }
     if (!is_array($va_tmp = self::rewriteQueryAndParams($ps_sql, $pa_values))) {
         $po_caller->postError(250, _t("Query rewrite failed"), "Db->pdo_mysql->execute()");
         return false;
     }
     if ($va_tmp['prepare']) {
         $opo_statement = $this->opr_db->prepare($va_tmp['sql']);
     }
     if (Db::$monitor) {
         $t = new Timer();
     }
     try {
         $opo_statement->closeCursor();
         $opo_statement->execute(is_array($va_tmp['values']) && sizeof($va_tmp['values']) ? array_values($va_tmp['values']) : null);
     } catch (PDOException $e) {
         $po_caller->postError($po_caller->nativeToDbError($this->opr_db->errorCode()), $e->getMessage() . (__CA_ENABLE_DEBUG_OUTPUT__ ? "\n<pre>" . caPrintStacktrace() . "\n{$ps_sql}</pre>" : ""), "Db->pdo_mysql->execute()");
         return false;
     }
     if (Db::$monitor) {
         Db::$monitor->logQuery($ps_sql, $pa_values, $t->getTime(4), $opo_statement->rowCount());
     }
     return new DbResult($this, $opo_statement);
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:41,代码来源:pdo_mysql.php

示例11: is_connected

 /**
  * Check if server is still connected
  * @return bool
  */
 public function is_connected()
 {
     if (!$this->dbh || 2006 == $this->dbh->errorCode()) {
         return false;
     }
     return true;
 }
开发者ID:mpeshev,项目名称:wp-db-driver,代码行数:11,代码来源:pdo_mysql.php

示例12: errorCode

 public function errorCode()
 {
     if ($this->pdo == null) {
         return null;
     }
     return $this->pdo->errorCode();
 }
开发者ID:shabbyrobe,项目名称:pdok,代码行数:7,代码来源:Connector.php

示例13: db_query

/**
 * 数据库查询方法
 * sql		sql语句
 * ret_type	返回类型,result/row/rows/value
 **/
function db_query(PDO $db, $sql, $ret_type = 'result')
{
    /*$s = db_parsesql($sql);
    	if(!$s){
    		return false;
    	}
    	*/
    if ($ret_type == 'result') {
        $result = $db->exec($sql);
    } else {
        $result = $db->query($sql);
    }
    if (!$result && $db->errorCode() != '00000') {
        //trigger_error('在MYSQL服务器端执行SQL语句失败.<br />SQL: ' . $sql . '<br />原因: '. $db->errorCode() . '<br />');
        return false;
    }
    switch ($ret_type) {
        case "result":
            return $result;
        case "row":
            if ($result) {
                return $result->fetch();
            }
            return false;
        case "rows":
            if ($result) {
                return $result->fetchAll(PDO::FETCH_ASSOC);
            }
            return false;
        default:
            trigger_error(__FUNCTION__ . " unknowd query type");
            return false;
    }
}
开发者ID:srdc2014,项目名称:vhms,代码行数:39,代码来源:db.lib.php

示例14: testPDOConnectionError

 public function testPDOConnectionError()
 {
     $string_dsn = 'mysql:host= nosuchhost;dbname=nosuchdb';
     $mypdo = new PDO($string_dsn, "nonesuchuser", "nonesuchpass");
     // Should be an error set since we gave bogus info
     $this->assertTrue(strlen($mypdo->errorCode()) > 0, "Error code not being set on PDO object");
 }
开发者ID:christianseel,项目名称:xpdo,代码行数:7,代码来源:PDOTest.php

示例15: getMeetups

 /**
  * @return Meetup[]
  */
 public function getMeetups()
 {
     $statement = $this->pdo->query('SELECT m.*, count(r.member_identifier) as taken
          FROM meetups m
          LEFT JOIN rsvps r ON (r.meetup_identifier = m.identifier AND r.rsvp = "yes")
          GROUP BY m.identifier
          ORDER BY m.date ASC');
     if (false === $statement) {
         throw new \PDOException(join("\n", $this->pdo->errorInfo()), $this->pdo->errorCode());
     }
     $meetups = [];
     while ($row = $statement->fetch(\PDO::FETCH_OBJ)) {
         $meetups[] = $this->rowToMeetup($row);
     }
     return $meetups;
 }
开发者ID:belanur,项目名称:docker-example,代码行数:19,代码来源:MeetupReader.php


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