PHP PDO函數(shù)庫(kù)(PDO Functions)第1/2頁(yè)
更新時(shí)間:2009年07月20日 22:51:07 作者:
PDO是一個(gè)“數(shù)據(jù)庫(kù)訪問(wèn)抽象層”,作用是統(tǒng)一各種數(shù)據(jù)庫(kù)的訪問(wèn)接口,與mysql和mysqli的函數(shù)庫(kù)相比,PDO讓跨數(shù)據(jù)庫(kù)的使用更具有親和力.
與ADODB和MDB2相比,PDO更高效。目前而言,實(shí)現(xiàn)“數(shù)據(jù)庫(kù)抽象層”任重而道遠(yuǎn),使用PDO這樣的“數(shù)據(jù)庫(kù)訪問(wèn)抽象層”是一個(gè)不錯(cuò)的選擇。
PDO->beginTransaction() — 標(biāo)明回滾起始點(diǎn)
PDO->commit() — 標(biāo)明回滾結(jié)束點(diǎn),并執(zhí)行SQL
PDO->__construct() — 建立一個(gè)PDO鏈接數(shù)據(jù)庫(kù)的實(shí)例
PDO->errorCode() — 獲取錯(cuò)誤碼
PDO->errorInfo() — 獲取錯(cuò)誤的信息
PDO->exec() — 處理一條SQL語(yǔ)句,并返回所影響的條目數(shù)
PDO->getAttribute() — 獲取一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”的屬性
PDO->getAvailableDrivers() — 獲取有效的PDO驅(qū)動(dòng)器名稱
PDO->lastInsertId() — 獲取寫入的最后一條數(shù)據(jù)的主鍵值
PDO->prepare() — 生成一個(gè)“查詢對(duì)象”
PDO->query() — 處理一條SQL語(yǔ)句,并返回一個(gè)“PDOStatement”
PDO->quote() — 為某個(gè)SQL中的字符串添加引號(hào)
PDO->rollBack() — 執(zhí)行回滾
PDO->setAttribute() — 為一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”設(shè)定屬性
PDOStatement->bindColumn() — Bind a column to a PHP variable
PDOStatement->bindParam() — Binds a parameter to the specified variable name
PDOStatement->bindValue() — Binds a value to a parameter
PDOStatement->closeCursor() — Closes the cursor, enabling the statement to be executed again.
PDOStatement->columnCount() — Returns the number of columns in the result set
PDOStatement->errorCode() — Fetch the SQLSTATE associated with the last operation on the statement handle
PDOStatement->errorInfo() — Fetch extended error information associated with the last operation on the statement handle
PDOStatement->execute() — Executes a prepared statement
PDOStatement->fetch() — Fetches the next row from a result set
PDOStatement->fetchAll() — Returns an array containing all of the result set rows
PDOStatement->fetchColumn() — Returns a single column from the next row of a result set
PDOStatement->fetchObject() — Fetches the next row and returns it as an object.
PDOStatement->getAttribute() — Retrieve a statement attribute
PDOStatement->getColumnMeta() — Returns metadata for a column in a result set
PDOStatement->nextRowset() — Advances to the next rowset in a multi-rowset statement handle
PDOStatement->rowCount() — Returns the number of rows affected by the last SQL statement
PDOStatement->setAttribute() — Set a statement attribute
PDOStatement->setFetchMode() — Set the default fetch mode for this statement
從函數(shù)列表可以看出,操作基于不同的對(duì)象,“PDO”表示的是一個(gè)數(shù)據(jù)庫(kù)連接對(duì)象(new PDO產(chǎn)生),“PDOStatement”表示的是一個(gè)查詢對(duì)象(PDO->query()產(chǎn)生)或者是一個(gè)結(jié)果集對(duì)象(PDO->prepare()產(chǎn)生)。
一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”的例子,返回“PDO”:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', '');
?>
一個(gè)“查詢對(duì)象”的例子,返回“PDOStatement”:
<?php
$sql = "INSERT INTO `test`.`table` (`name` ,`age`)VALUES (?, ?);";
$stmt = $dbh->prepare($sql);
?>
一個(gè)“結(jié)果集對(duì)象”的例子,返回“PDOStatement”:
<?php
$sql = "SELECT * FROM `table` WHERE `name` = 'samon'";
$stmt = $dbh->query($sql);
?>
PDO->beginTransaction() — 標(biāo)明回滾起始點(diǎn)
PDO->commit() — 標(biāo)明回滾結(jié)束點(diǎn),并執(zhí)行SQL
PDO->__construct() — 建立一個(gè)PDO鏈接數(shù)據(jù)庫(kù)的實(shí)例
PDO->errorCode() — 獲取錯(cuò)誤碼
PDO->errorInfo() — 獲取錯(cuò)誤的信息
PDO->exec() — 處理一條SQL語(yǔ)句,并返回所影響的條目數(shù)
PDO->getAttribute() — 獲取一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”的屬性
PDO->getAvailableDrivers() — 獲取有效的PDO驅(qū)動(dòng)器名稱
PDO->lastInsertId() — 獲取寫入的最后一條數(shù)據(jù)的主鍵值
PDO->prepare() — 生成一個(gè)“查詢對(duì)象”
PDO->query() — 處理一條SQL語(yǔ)句,并返回一個(gè)“PDOStatement”
PDO->quote() — 為某個(gè)SQL中的字符串添加引號(hào)
PDO->rollBack() — 執(zhí)行回滾
PDO->setAttribute() — 為一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”設(shè)定屬性
PDOStatement->bindColumn() — Bind a column to a PHP variable
PDOStatement->bindParam() — Binds a parameter to the specified variable name
PDOStatement->bindValue() — Binds a value to a parameter
PDOStatement->closeCursor() — Closes the cursor, enabling the statement to be executed again.
PDOStatement->columnCount() — Returns the number of columns in the result set
PDOStatement->errorCode() — Fetch the SQLSTATE associated with the last operation on the statement handle
PDOStatement->errorInfo() — Fetch extended error information associated with the last operation on the statement handle
PDOStatement->execute() — Executes a prepared statement
PDOStatement->fetch() — Fetches the next row from a result set
PDOStatement->fetchAll() — Returns an array containing all of the result set rows
PDOStatement->fetchColumn() — Returns a single column from the next row of a result set
PDOStatement->fetchObject() — Fetches the next row and returns it as an object.
PDOStatement->getAttribute() — Retrieve a statement attribute
PDOStatement->getColumnMeta() — Returns metadata for a column in a result set
PDOStatement->nextRowset() — Advances to the next rowset in a multi-rowset statement handle
PDOStatement->rowCount() — Returns the number of rows affected by the last SQL statement
PDOStatement->setAttribute() — Set a statement attribute
PDOStatement->setFetchMode() — Set the default fetch mode for this statement
從函數(shù)列表可以看出,操作基于不同的對(duì)象,“PDO”表示的是一個(gè)數(shù)據(jù)庫(kù)連接對(duì)象(new PDO產(chǎn)生),“PDOStatement”表示的是一個(gè)查詢對(duì)象(PDO->query()產(chǎn)生)或者是一個(gè)結(jié)果集對(duì)象(PDO->prepare()產(chǎn)生)。
一個(gè)“數(shù)據(jù)庫(kù)連接對(duì)象”的例子,返回“PDO”:
復(fù)制代碼 代碼如下:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', '');
?>
一個(gè)“查詢對(duì)象”的例子,返回“PDOStatement”:
復(fù)制代碼 代碼如下:
<?php
$sql = "INSERT INTO `test`.`table` (`name` ,`age`)VALUES (?, ?);";
$stmt = $dbh->prepare($sql);
?>
一個(gè)“結(jié)果集對(duì)象”的例子,返回“PDOStatement”:
復(fù)制代碼 代碼如下:
<?php
$sql = "SELECT * FROM `table` WHERE `name` = 'samon'";
$stmt = $dbh->query($sql);
?>
您可能感興趣的文章:
- php_pdo 預(yù)處理語(yǔ)句詳解
- php PDO實(shí)現(xiàn)的事務(wù)回滾示例
- php pdo操作數(shù)據(jù)庫(kù)示例
- php基于PDO實(shí)現(xiàn)功能強(qiáng)大的MYSQL封裝類實(shí)例
- php使用PDO執(zhí)行SQL語(yǔ)句的方法分析
- PHP5中使用PDO連接數(shù)據(jù)庫(kù)的方法
- php使用pdo連接報(bào)錯(cuò)Connection failed SQLSTATE的解決方法
- php使用pdo連接并查詢sql數(shù)據(jù)庫(kù)的方法
- php中PDO方式實(shí)現(xiàn)數(shù)據(jù)庫(kù)的增刪改查
- php中mysql連接方式PDO使用詳解
- PHP實(shí)現(xiàn)PDO的mysql數(shù)據(jù)庫(kù)操作類
- 關(guān)于PHPDocument 代碼注釋規(guī)范的總結(jié)
- php實(shí)現(xiàn)基于PDO的預(yù)處理示例
相關(guān)文章
PHP定時(shí)任務(wù)獲取微信access_token的方法
這篇文章主要介紹了PHP定時(shí)任務(wù)獲取微信access_token的方法,涉及php基于curl動(dòng)態(tài)獲取access_token及CentOS下crontab設(shè)置計(jì)劃任務(wù)的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
php抽獎(jiǎng)概率算法(刮刮卡,大轉(zhuǎn)盤)
這篇文章主要為大家詳細(xì)介紹了php中獎(jiǎng)概率算法,可用于刮刮卡,大轉(zhuǎn)盤等抽獎(jiǎng)算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
PHP+JavaScript實(shí)現(xiàn)無(wú)刷新上傳圖片
本文主要介紹了PHP+JavaScript實(shí)現(xiàn)無(wú)刷新上傳圖片的方法,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02
PHP實(shí)現(xiàn)通過(guò)URL提取根域名
本文給大家分享的是個(gè)人在做項(xiàng)目的時(shí)候遇到的,需要通過(guò)php實(shí)現(xiàn)從URL中提取根域名的代碼以及實(shí)現(xiàn)思路,有需要的小伙伴可以參考下2016-03-03
PHP-FPM運(yùn)行狀態(tài)的實(shí)時(shí)查看及監(jiān)控詳解
php-fpm和nginx一樣內(nèi)建了一個(gè)狀態(tài)頁(yè),對(duì)于想了解php-fpm的狀態(tài)以及監(jiān)控php-fpm非常有幫助。這篇文章就給大家詳細(xì)介紹了PHP-FPM運(yùn)行狀態(tài)的實(shí)時(shí)查看及監(jiān)控,有需要的朋友們可以參考學(xué)習(xí),感興趣的朋友們下面來(lái)一起看看吧。2016-11-11
php5.5使用PHPMailer-5.2發(fā)送郵件的完整步驟
PHPMailer已經(jīng)更新了很多版本了,本教程只針對(duì)老版本。下面這篇文章主要給大家介紹了關(guān)于php5.5使用PHPMailer-5.2發(fā)送郵件的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
淺談ThinkPHP中initialize和construct的區(qū)別
下面小編就為大家?guī)?lái)一篇淺談ThinkPHP中initialize和construct的區(qū)別。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04

