本文整理汇总了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');
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例10: step3
function step3()
{
$support = pdo::getAvailableDrivers();
if (!$support) {
$this->errorOutput("PDO不支持任何数据库驱动");
}
$this->addItem($support);
$this->output();
}
示例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);
}
示例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;
}
}
示例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));
}
示例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;
}
示例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;
}