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


PHP pdo類代碼示例

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


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

示例1: postCheckdb

 public function postCheckdb()
 {
     if (!Session::get('step2')) {
         return Redirect::to('install/step2');
     }
     $dbhost = Input::get('dbhost');
     $dbuser = Input::get('dbuser');
     $dbpass = Input::get('dbpass');
     $dbname = Input::get('dbname');
     Session::put(array('dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbname' => $dbname));
     try {
         $dbh = new pdo("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
         $sql = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/dump.sql');
         $result = $dbh->exec($sql);
         $databaseFile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/database.php');
         $databaseFile = str_replace(array('{DBHOST}', '{DBNAME}', '{DBUSER}', '{DBPASS}'), array($dbhost, $dbname, $dbuser, $dbpass), $databaseFile);
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/database.php', $databaseFile);
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/database.php', $databaseFile);
         Session::put('step3', true);
         return Illuminate\Support\Facades\Redirect::to('install/step4');
     } catch (PDOException $ex) {
         Session::put('step3', false);
         return Illuminate\Support\Facades\Redirect::to('install/step3')->with('conerror', 'Date invalide');
     }
 }
開發者ID:vcorobceanu,項目名稱:WebAPL,代碼行數:25,代碼來源:InstallController.php

示例2: __construct

 function __construct($host, $username, $password, $db)
 {
     $conn_para = "mysql:{$host};{$db};charset=utf8";
     $opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
     $this->_pdo = new PDO($conn_para, $username, $password, $opt) or die('There is problem in connecting to database');
     $this->_pdo->exec("USE " . $db);
     self::$_instance = $this;
 }
開發者ID:antoniomerlin,項目名稱:PHP-PDO-Database-Class,代碼行數:8,代碼來源:PDO_DB.php

示例3: dbConnect

function dbConnect($timeout, $options = array())
{
    $db = new pdo(PDO_dsn, PDO_username, PDO_password);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $db->setAttribute(PDO::ATTR_TIMEOUT, "0");
    foreach ($options as $option) {
        $db->exec($option);
    }
    return $db;
}
開發者ID:blublud,項目名稱:SocialCrawler,代碼行數:10,代碼來源:pdoReconnect.php

示例4: getAll

 public static function getAll()
 {
     $lijst = array();
     $dbh = new pdo(dbconfigpizzeria::$DB_CONNSTRING, dbconfigpizzeria::$DB_USERNAME, dbconfigpizzeria::$DB_PASSWORD);
     $sql = "select * from klanten";
     $resultSet = $dbh->query($sql);
     foreach ($resultSet as $rij) {
         $pizza = new Pizza($rij["voornaam"], $rij["familienaam"], $rij["email"], $rij["wachtwoord"]);
         $lijst[] = $pizza;
     }
     $dbh = null;
     return $lijst;
 }
開發者ID:Thomasvc1,項目名稱:Eindtest-php,代碼行數:13,代碼來源:klantdao.class.php

示例5: getAll

 public static function getAll()
 {
     $lijst = array();
     $dbh = new pdo(dbconfigpizzeria::$DB_CONNSTRING, dbconfigpizzeria::$DB_USERNAME, dbconfigpizzeria::$DB_PASSWORD);
     $sql = "select * from extras";
     $resultSet = $dbh->query($sql);
     foreach ($resultSet as $rij) {
         $extra = new Extra($rij["extraid"], $rij["omschrijving"], $rij["prijs"]);
         $lijst[] = $extra;
     }
     $dbh = null;
     return $lijst;
 }
開發者ID:Thomasvc1,項目名稱:Eindtest-php,代碼行數:13,代碼來源:extradao.class.php

示例6: getDb

 /**
  * Get Database PDO connection
  * @param - no param
  * @return pdo
  */
 public function getDb()
 {
     if (self::$pdo == null) {
         $dsn = DBENGINE . ':dbname=' . DATABASE . ';host=' . HOST . ';portname=' . PORTNAME . ';';
         try {
             self::$pdo = new PDO($dsn, USERNAME, PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
             //Enabling exceptions
             self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             echo $e->getMessage();
         }
     }
     return self::$pdo;
 }
開發者ID:asbag,項目名稱:WebServicesRestful,代碼行數:19,代碼來源:Database.php

示例7: displayMsgUser

 public function displayMsgUser(pdo $conexao, $idUsuario)
 {
     try {
         $msg = "";
         $stmtSel = $conexao->prepare(mensagemDAO::$SELECT_MENSAGEM_USER);
         $stmtSel->execute(array(':idUsuario' => $idUsuario));
         $resultado = $stmtSel->fetchAll();
         foreach ($resultado as $linha) {
             $msg .= "<div class='listMsg'>\n                        <span class='usuario1'>{$linha['3']}</span>";
         }
         return $msg;
     } catch (PDOException $e) {
         print_r($e);
     }
 }
開發者ID:andremurilo,項目名稱:escola-ingles,代碼行數:15,代碼來源:mensagemDAO.class.php

示例8: executeQuery

 /**
  * This method will execute sql query.
  *
  * @param queryId - The query id to execute. if no value is given the method will seach for it as request param.
  * @param params -  List of parameters to bind to teh stored procedure.
  *                  If no parameters are passed all the request params will be used as bind parameters.
  *
  * @return - Returns an array containing all of the result set rows
  */
 public function executeQuery($queryId = null, $params = null)
 {
     if (!isset($queryId)) {
         $queryId = Utils::getParam('queryId', null);
         if (!isset($queryId)) {
             throw new Exception('Missing queryId');
         }
     }
     // -----------------------------------------------------------------------------------
     // -- If no parameters are passed auto build the params from all the GET/POST pairs --
     // -----------------------------------------------------------------------------------
     if (!isset($params)) {
         $params = array();
         // We read the parameters form the request since it contains both get and post params
         foreach ($_REQUEST as $key => $value) {
             $params[':' . $key] = $value;
         }
     }
     // Get the query we wish to execute
     $query = $this->sql_queries[$queryId];
     $statment = $this->pdo->prepare($query);
     $statment->setFetchMode(PDO::FETCH_ASSOC);
     $statment->execute($params);
     // Check to see if we have error or not
     $error = $statment->errorInfo();
     // Set the error message
     if ($error[0] > 0) {
         $_REQUEST['DBLayer.executeQuery.error'] = $statment->errorInfo();
     }
     // return all the rows
     return $statment->fetchAll();
 }
開發者ID:nirgeier,項目名稱:CodeBlue_Project,代碼行數:41,代碼來源:DBLayer.php

示例9: gc

 /**
 * The garbage collector deletes all sessions from the database
 * that where not deleted by the session_destroy function.
 * so your session table will stay clean.
 *
 * @access public
 * @access Integer $maxlifetime The maximum session lifetime
 * @return Boolean
 */
 public function gc($maxlifetime)
 {
     // Set a period after that a session pass off.
     $maxlifetime = strtotime("-20 minutes");
     // Setup a query to delete discontinued sessions, ...
     $delete = "DELETE FROM `sessions` WHERE `sessions`.`last_updated` < :maxlifetime;";
     $result = $this->pdo->query($delete, array("maxlifetime" => $maxlifetime));
     return $result;
 }
開發者ID:roiKosmic,項目名稱:chiconServer,代碼行數:18,代碼來源:MySqlSession.class.php

示例10: step3

 function step3()
 {
     $support = pdo::getAvailableDrivers();
     if (!$support) {
         $this->errorOutput("PDO不支持任何數據庫驅動");
     }
     $this->addItem($support);
     $this->output();
 }
開發者ID:h3len,項目名稱:Project,代碼行數:9,代碼來源:data.php

示例11: test_getMessageIDfromQueue_2

 public function test_getMessageIDfromQueue_2()
 {
     $name = 'getMessageIDfromQueue 2';
     $mq_id = $this->m->addQueue($name);
     $method = new ReflectionMethod('phpMQ\\pdom', 'getMessageIDfromQueue');
     $method->setAccessible(TRUE);
     $mid_get = $method->invoke($this->setUp(), $mq_id);
     $this->assertEquals(FALSE, $mid_get);
 }
開發者ID:MayuriKadam,項目名稱:phpMQ,代碼行數:9,代碼來源:pdoTest.php

示例12: updateInformation

 public function updateInformation($table, $update, $where, $val)
 {
     foreach ($update as $key => $value) {
         $x++;
         $set .= "" . $key . " = " . $value . "";
         if (count($update) > $x) {
             $set .= ", ";
         }
     }
     try {
         $db = new pdo($this->db_config["host"], $this->db_config["user"], $this->db_config["pswd"]);
         $sql = $db->prepare("UPDATE " . $table . " SET " . $set . " WHERE " . $where . " = " . $val . "");
         $sql->execute();
         unset($db);
         return $row;
     } catch (PDOException $e) {
         die("Database Error: " . $e);
         return false;
     }
 }
開發者ID:Cryptogenic,項目名稱:PHPBot-Xat,代碼行數:20,代碼來源:database.module.php

示例13: setAllMsgDeleteInThread

    public function setAllMsgDeleteInThread($threadId)
    {
        $sql = $this->getQuery('UPDATE ' . self::$SCHEMA . '.MSG_BOX set "Status"=(
																CASE WHEN ( "To_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$DELETED_BY_FROM_USER . ') THEN ' . self::$DELETED_BY_BOTH . '
																	 WHEN ( "From_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$DELETED_BY_TO_USER . ') THEN ' . self::$DELETED_BY_BOTH . '
																	 WHEN "From_User_ID" = ' . $this->userId . ' AND "Status" = ' . self::$NOT_READED . ' THEN ' . self::$DELETED_FROM_USER_NOT_READED_BY_TO_USER . '
																	 WHEN "To_User_ID" = ' . $this->userId . ' THEN ' . self::$DELETED_BY_TO_USER . '
																	 WHEN "From_User_ID" = ' . $this->userId . ' THEN ' . self::$DELETED_BY_FROM_USER . '
																END )
				 WHERE "MSG_ID" in (Select "ID" from ' . self::$SCHEMA . '.MSG where "Thread_ID"=?) AND ("To_User_ID"=' . $this->userId . ' OR "From_User_ID"=' . $this->userId . ')');
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute(array($threadId));
    }
開發者ID:xop32,項目名稱:phpPM,代碼行數:13,代碼來源:MSGBox.php

示例14: unlock

 /**
  * Removes a lock from a uri
  *
  * @param string $uri
  * @param LockInfo $lockInfo
  * @return bool
  */
 function unlock($uri, LockInfo $lockInfo)
 {
     $stmt = $this->pdo->prepare('DELETE FROM ' . $this->tableName . ' WHERE uri = ? AND token = ?');
     $stmt->execute([$uri, $lockInfo->token]);
     return $stmt->rowCount() === 1;
 }
開發者ID:sebbie42,項目名稱:casebox,代碼行數:13,代碼來源:PDO.php

示例15: unlock

 /**
  * Removes a lock from a uri 
  * 
  * @param string $uri 
  * @param Sabre_DAV_Locks_LockInfo $lockInfo 
  * @return bool 
  */
 public function unlock($uri, Sabre_DAV_Locks_LockInfo $lockInfo)
 {
     $stmt = $this->pdo->prepare('DELETE FROM locks WHERE uri = ? AND token = ?');
     $stmt->execute(array($uri, $lockInfo->token));
     return $stmt->rowCount() === 1;
 }
開發者ID:rolwi,項目名稱:koala,代碼行數:13,代碼來源:PDO.php


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