本文整理汇总了PHP中pdo类的典型用法代码示例。如果您正苦于以下问题:PHP pdo类的具体用法?PHP pdo怎么用?PHP pdo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pdo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: catch
} catch (PDOException $e) {
$_SESSION["message"] = "Error: " . $e;
header('location: gegevens-wijzigen-form.php');
}
} else {
$_SESSION['message'] = "ERROR. De file is geen jpeg/gif/png bestand. Het is een " . $typeBestand . " bestand.";
}
} else {
$_SESSION['message'] = "Er werd geen nieuwe profielfoto geselecteerd";
}
if (isset($_POST['updateEmail'])) {
$updatedEmail = $_POST['updateEmail'];
$isEmail = filter_var($updatedEmail, FILTER_VALIDATE_EMAIL);
if ($isEmail) {
if ($currentEmail != $updatedEmail) {
$db = new pdo('mysql:host=localhost;dbname=users-fileupload', 'root', '');
$updateEmailQuery = "UPDATE users SET email='{$updatedEmail}' WHERE email='{$currentEmail}';";
$updateEmail = $db->prepare($updateEmailQuery);
$updateEmail->execute();
setcookie("login", time() - 500);
setcookie("login", $updatedEmail, time() + 86400 * 30);
$_SESSION['message'] = "Emailadres werd gewijzigd naar " . $updatedEmail;
} else {
$_SESSION['message'] = "Het emailadres werd niet veranderd. Huidig emailadres: |" . $currentEmail . " | Nieuw emailadres: |" . $updatedEmail . " | En de cookievalue zegt: |" . $getCookie[0] . "|";
}
} else {
$_SESSION['message'] = "Dit is geen emailadres.";
}
} else {
$_SESSION['message'] = "Je moet een emailadres opgeven.";
}
开发者ID:RobinDeHerdt,项目名称:web-backend-oplossingen,代码行数:31,代码来源:gegevens-bewerken.php
示例17: error_reporting
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
ob_start();
session_start();
// Create a connection.
$DB = null;
if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') !== false) {
// Connect from App Engine.
try {
$DB = new pdo('mysql:unix_socket=/cloudsql/motivatestudy-967:db; dbname=motivate', 'root', '');
} catch (PDOException $ex) {
die(json_encode(array('outcome' => false, 'message' => 'Unable to connect.')));
}
} else {
// Connect from a development environment.
try {
$DB = new pdo('mysql:host=localhost; dbname=ODK_Local', 'root', 'root');
} catch (PDOException $ex) {
die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
}
}
//get error/success messages
if ($_SESSION["errorType"] != "" && $_SESSION["errorMsg"] != "") {
$ERROR_TYPE = $_SESSION["errorType"];
$ERROR_MSG = $_SESSION["errorMsg"];
$_SESSION["errorType"] = "";
$_SESSION["errorMsg"] = "";
}
/*
* Session verification. If no session value page redirect to login.php
*/
$mode = $_REQUEST["mode"];
开发者ID:echiteri,项目名称:motivate_study_web_app,代码行数:31,代码来源:config.php
示例18: session_start
<?php
session_start();
$link = str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']);
$zoekterm = '';
$jaar = 2010;
$fetchRow = array();
$message = '';
if (isset($_SESSION['notification'])) {
$message = $_SESSION['notification'];
unset($_SESSION['notification']);
}
try {
$db = new pdo('mysql:host=localhost;dbname=opdracht_mod_rewrite_blog', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
if (isset($_GET['zoekInArtikel'])) {
$zoekterm = 'artikels die het woord "' . $_GET['artikel'] . '" bevatten';
$zoekArtikelQueryString = "Select * from artikels\n WHERE artikel LIKE :artikel";
$statement2 = $db->prepare($zoekArtikelQueryString);
$statement2->bindValue(':artikel', '%' . $_GET['artikel'] . '%');
$statement2->execute();
$fetchRow = array();
while ($row = $statement2->fetch(PDO::FETCH_ASSOC)) {
$fetchRow[] = $row;
}
}
if (isset($_GET['zoekOpDatum'])) {
$jaar = $_GET['jaar'];
$zoekterm = 'artikels geschreven in "' . $_GET['jaar'] . '"';
$zoekOpDatumQueryString = "Select * from artikels\n WHERE year(Datum) = :jaar";
$statement3 = $db->prepare($zoekOpDatumQueryString);
$statement3->bindValue(':jaar', $_GET['jaar']);
开发者ID:arnevanbavel,项目名称:web-backend-2015-2016,代码行数:31,代码来源:artikel-zoeken.php
示例19: pdo
<?php
if (isset($_POST["submit"])) {
try {
$db = new pdo('mysql:host=localhost;dbname=bieren', 'root', '');
// Root password not set up
$message = "db init";
$brNaam = $_POST["brouwernaam"];
$adres = $_POST["adres"];
$postcode = $_POST["postcode"];
$gemeente = $_POST["gemeente"];
$omzet = $_POST["omzet"];
$insertQuery = "INSERT INTO brouwers (brnaam, adres, postcode, gemeente, omzet) VALUES('{$brNaam}','{$adres}','{$postcode}','{$gemeente}','{$omzet}');";
// var_dump("INSERT INTO brouwers (brnaam, adres, postcode, gemeente, omzet) VALUES(" . $brNaam . ", " . $adres . ", ". $postcode . ", " . $gemeente . ", " . $omzet . ");");
$statement = $db->prepare($insertQuery);
$isAdded = $statement->execute();
if ($isAdded) {
$id = $db->lastInsertId();
// Returns id of the last inserted row
$message = 'Brouwerij succesvol toegevoegd. Het unieke nummer van deze brouwerij is ' . $id . '.';
} else {
$message = 'Er ging iets mis met het toevoegen, probeer opnieuw';
}
} catch (PDOException $e) {
$message = 'De connectie is niet gelukt.';
}
}
?>
<!doctype html>
<html>
开发者ID:RobinDeHerdt,项目名称:web-backend-oplossingen,代码行数:31,代码来源:opdracht-CRUD-insert.php
示例20: pdoToBean
/**
* Converts the given Person PDO to a bean object.
* This includes the conversion from nested lists
* of PDO objects to usable lists of oids/names to be used
* by the page renderer.
*
* @access private
* @param pdo $pdo Person
* @return bean Person
*/
private function pdoToBean($pdo)
{
global $logger;
$logger->debug(get_class($this) . "::pdoToBean({$pdo})");
// if this is an artist, be sure to get the artist PDO not the person
$scope = $pdo->getScope();
$id = $pdo->getOid();
if ($scope == 'Artist') {
$epm = epManager::instance();
$pdo = $epm->get('Artist', $id);
}
$bean = new $scope($pdo->epGetVars());
// pubState to a string
$ps = '';
if ($pdo->getPubState() != null) {
$ps = $pdo->getPubState()->getValue();
}
$bean->setPubState($ps);
// if it is an artist, convert the exhibitions
if (get_class($bean) == 'Artist') {
$exhibitions = $pdo->exhibitions;
if ($exhibitions) {
$related = array();
foreach ($exhibitions as $event) {
$related[] = new Exhibition($event->epGetVars());
}
$bean->setExhibitions($related);
}
}
return $bean;
}
开发者ID:justinlyon,项目名称:scc,代码行数:41,代码来源:PersonService.php
注:本文中的pdo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论