当前位置: 首页>>代码示例>>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;未经允许,请勿转载。