PHP Data Objects (PDO)

Source: Internet
Author: User

to be The PHP Access database defines a lightweight, consistent interface. Each database driver that implements the PDO interface can expose the characteristics of a specific database as a standard extension feature. Note that using PDO to extend itself does not enable any database functionality; You must use the PDO driver for a specific database to access the database service.

PDO provides a data access abstraction layer, which means that the same functions (methods) can be used to query and fetch data regardless of the database used. PDO does not provide a database abstraction layer; it does not rewrite SQL, nor does it emulate missing attributes. If necessary, use a mature abstraction layer.

the connection string for the database, including the database type, the connected library name, the connected address, the connected port number, the connected character set

For example :

$dsn ='mysql:dbname=pg39;host=127.0.0.1;port=13306;charset=utf8'

users accessing the data

$user ='root';

password to access the database

$password =";

Creating a PDO object that connects the operations database MySQL

$DBH =new PDO ($dsn, $user, $password);

define SQL statements sent to database server side execution and return results

$pt = $dbh->query (' select*from student ', pdo::fetch_num);

action and Extract return value results

$arr =array ();

foreach ($pt as $val) {

Array_push ($arr, $val);

}

Var_dump ($arr);

close the data object after the Operation

$DBH =null;

all the DML Operations Use the exec function, the return value is the number of rows affected, the integer value

Parse_ini_file: parsing a configuration file

For example :

if (file_exists (' db ')) {
$ini _array= @parse_ini_file ("db");
Print_r ($ini _array);
}

PHP Data Objects (PDO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.