<meta charset= "Utf-8" /><?php/*1. What is PDO---->PHP Data The OBJECTPDO extension defines a lightweight, consistent interface for the PHP Access database, which provides a database access abstraction layer so that queries can be executed and data retrieved 2 by consistent functions, regardless of the database used. PHP&NBSP;PDO is configured in the PHP5 series version, PDO is not supported by default and requires manual configuration to be used. Open the php.ini file and remove the Extension=php_pdo.dllextension=php_pdo_mysql.dll configuration before the ; symbol to make php Support &NBSP;PDO configuration after you save the configuration and restart Apache Web services, you can check whether the configuration was successful by phpinfo () . 3.pdo Create a connection before you use the PDO operations database, you need to create PDO connect objects. Syntax: New pdo (dsn, username, password); different database, its &NBSP;DSN (data source name) Constructed in a way that is not the same as//mysql:mysql:host=hostname;dbname=db_name)//sqlite:sqlite:db_name4. Pdo->query () is used to query data records and return query results, such as SELECT operations. pdo->query ( string statement ) *///construction PDO Connection $dbh = "mysql:host= Localhost;dbname=test "; $db = new pdo ($dbh, ' root ', ' 123456 '); $db->query (" set character set ' UTF8 ');//Query Data $sql = "Select * from stu_info "; $sth = $db->query ($sql);//$sth is the result set object//$sth Setfetchmode (PDO::FETCH_ASSOC);// If you do not specify the result type returned in Setfetchmode (), you can also use the FETCH () method to set the while ($row = $ Sth->fetch (PDO::FETCH_ASSOC)) {Print_r ($row);//array ( [id] => 1 [sname] = > admin [age] => 20 [addr] => beijing ) Associative arrays echo "User name:". $row [' sname ']. " "; echo "Age:". $row [' ages ']. "; echo "Address:". $row [' addr ']. " "; echo "
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/76/21/wKiom1ZK5m_znAKLAABRHcUp5Dg885.png "title=" Qq20151117163340.png "alt=" Wkiom1zk5m_znaklaabrhcup5dg885.png "/>
This article is from the "IT5808" blog, make sure to keep this source http://it5808.blog.51cto.com/10842703/1713532
PDO Operation MySQL Database-01