PDO Operation MySQL Database-01

Source: Internet
Author: User

<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 ']. " &nbsp;&nbsp; ";     echo  "Age:". $row [' ages ']. &nbsp;&nbsp; ";     echo  "Address:". $row [' addr ']. " &nbsp;&nbsp; ";     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

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.