MySQLPDO connection and operations

Source: Internet
Author: User
: This article mainly introduces the connection and operation of MySQLPDO. if you are interested in the PHP Tutorial, refer to it.

// The parameter for instantiating the PDO connection database is mysql: host = localhost; dbname = lamp username and password $ pdo = new PDO ('MySQL: host = localhost; dbname = lamp ', 'root ','');

// Query statement

$ SQL = "select * from lamp_login"; $ stmt = $ pdo-> query ($ SQL );

// Add, delete, and modify

$ Pdo-> exec ($ SQL );

PDO: FETCH_OBJ is equivalent to mysql_fetch_object

object(stdClass)[3]  public 'id' =>string'1'(length=1)  public 'username' =>string'user1'(length=5)  public 'password' =>string'123'(length=3)

PDO: FETCH_BOTH is equivalent to mysql_fetch_array

array(size=6)  'id' =>string'2'(length=1)  0 =>string'2'(length=1)  'username' =>string'user2'(length=5)  1 =>string'user2'(length=5)  'password' =>string'234'(length=3)  2 =>string'234'(length=3)

PDO: FETCH_NUM is equivalent to mysql_fetch_row

array(size=3)  0 =>string'3'(length=1)  1 =>string'user3'(length=5)  2 =>string'345'(length=3)

PDO: FETCH_ASSOC equivalent to mysql_fetch_assoc

array(size=3)  'id' =>string'4'(length=1)  'username' =>string'zhouyao'(length=7)  'password' =>string'123456'(length=6)

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the connection and operation of MySQL PDO, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.