標籤:ext instance const inf ror str array localhost end
PDO的方法/屬性
- PDO::beginTransaction — Initiates a transaction
- PDO::commit — Commits a transaction
- PDO::__construct — Creates a PDO instance representing a connection to a database //構造方法
- PDO::errorCode — Fetch the SQLSTATE associated with the last operation on the database handle
- PDO::errorInfo — Fetch extended error information associated with the last operation on the database handle
- PDO::exec — Execute an SQL statement and return the number of affected rows
- PDO::getAttribute — Retrieve a database connection attribute //獲得屬性
- PDO::getAvailableDrivers — Return an array of available PDO drivers
- PDO::inTransaction — Checks if inside a transaction
- PDO::lastInsertId — Returns the ID of the last inserted row or sequence value
- PDO::prepare — Prepares a statement for execution and returns a statement object
- PDO::query — Executes an SQL statement, returning a result set as a PDOStatement object
- PDO::quote — Quotes a string for use in a query.
- PDO::rollBack — Rolls back a transaction
- PDO::setAttribute — Set an attribute //設定屬性
PDO預定義常量 (PS:可以使用預定義常量來擷取一些伺服器或者用戶端的資訊)
http://www.runoob.com/php/php-pdo-constants.html
因為內容較多所以就不複製到文章當中了。
用法:
<?php try { $pdo = new PDO("mysql:host=localhost;port=3306;dbname=admin","root","");//如果PDO出現異常那麼就執行catch中的代碼。否則不執行catch進而繼續向下執行。} catch (Exception $e) { echo "資料庫連接失敗!".$e->getmessage(); exit;} echo $pdo->getattribute(PDO::ATTR_DRIVER_NAME); /* *getAttribute是擷取屬性的資訊,Attribute英譯為屬性。 *PDO::ATTR_DRIVER_NAME是返回驅動的名稱 * */ ?>
以上是是返回資訊,那麼自然也是可以設定的。
可以使用PDO::setAttribute來設定。
本來PDO::ATTR_AUTOCOMMIT是為開啟的,即為1.大家可以自己嘗試執行一下。
然後我們用serattribute來設定將其關閉,
跟著百度學PHP[14]-PDO的構造方法