: 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.