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


PHP pdo::errorInfo方法代碼示例

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


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

示例1: pdo

<?php

$pdo = new pdo("mysql:host=localhost;dbname=ders", "root", "");
$sorgu = $pdo->prepare("select * from ders") or die("Hata: " . $pdo->errorInfo()[2]);
$sorgu->execute();
foreach ($sorgu as $veri) {
    echo $veri[1];
}
開發者ID:hakandinceler,項目名稱:lyk2015php,代碼行數:8,代碼來源:Rastgele_Veri_sec.php

示例2: pdo

<?php

$db = new pdo('sqlite::memory:');
$db->query('CREATE TABLE IF NOT EXISTS foo (id INT AUTO INCREMENT, name TEXT)');
$db->query('INSERT INTO foo VALUES (NULL, "PHP")');
$db->query('INSERT INTO foo VALUES (NULL, "PHP6")');
var_dump($db->query('SELECT * FROM foo'));
var_dump($db->errorInfo());
var_dump($db->lastInsertId());
$db->query('DROP TABLE foo');
開發者ID:badlamer,項目名稱:hhvm,代碼行數:10,代碼來源:pdo_sqlite_lastinsertid.php

示例3: execute

 /**
  * Executes sql statement without any return value. Please consider the usage of 
  * prepared statements which is fully supported.
  *
  * <code>
  * <?php
  * dbConn::execute("INSERT INTO :prefix:user (username, registered) VALUES (:0, :1);", 'felix', (new DateTime));
  * ?>
  *
  * @param 	string 				$query The query in sql language.
  * @param 	multiple strings 	The values that will fill the variables in the query.
  * @static
  */
 public static function execute()
 {
     $argsCount = func_num_args();
     $par = array();
     // no query as parameter given
     if ($argsCount < 1) {
         throw new Exception("No Sql-Query given");
     }
     // if there are parameters, insert in
     if ($argsCount > 1) {
         // create array with parameters for pdo usage
         for ($i = 1; $i < $argsCount; $i++) {
             $key = ":" . ($i - 1);
             $par[$key] = func_get_arg($i);
         }
     }
     // insert table prefix
     $query = func_get_arg(0);
     $query = str_replace(":prefix:", dbConn::$tablePrefix, $query);
     // create pdo connection
     $db = new pdo("mysql:" . "host=" . dbConn::$host . ";" . "dbname=" . dbConn::$database . ";" . "charset=UTF8", dbConn::$username, dbConn::$password);
     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     try {
         // prepare and execute
         $sth = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
         if (!$sth) {
             throw new Exception($db->errorInfo());
         }
         $sth->execute($par);
     } catch (Exception $ex) {
         throw new Exception($ex->getMessage());
     }
     // close database connection
     $db = null;
 }
開發者ID:fhoner,項目名稱:smartdoorbell,代碼行數:48,代碼來源:dbConn.php


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