跟著百度學PHP[14]-PDO的構造方法

來源:互聯網
上載者:User

標籤: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的構造方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.