How to Use pdo in php and pdo in php

Source: Internet
Author: User

How to Use pdo in php and pdo in php

Pdo: Database abstraction layer features: Cross-Database Pre-processing transactions $ pdo = new PDO ('mysql: host = 127.0.0.1; dbname = test; charset = utf8', 'root ', 'root', 'error message'); connect to the database $ pdo-> query ('select * from user '); // execute the query $ pdo-> exec ('Update user set id = 2'); // execute add Delete modify $ data = $ stmt-> fetchAll (PDO :: FETCH_ASSOC); // extract data $ pdo-> lastInsertId () The most inserted id $ stmt-> rowCount () the number of affected rows. The error mode of PDO is getAttribute () get the error mode of pdo setAttribute () set the error mode of pdo $ pdo-> setAttribute (PDO: ATTR_ERR MODE, 2); PDO: ERRMODE_SILENT default 0 PDO: ERRMODE_WARNING warning 1 PDO: ERRMODE_EXCEPTION exception 2PDO prepare a preprocessing statement? Placeholder $ stmt = $ pdo-> prepare ("insert into user (username, password, sex, age) values (?,?,?,?) "); 1. assign a value to the placeholder $ stmt-> bindValue (1, 'Liu Yan'); 2. assign $ stmt-> bindParam (1, $ username); 3 to the placeholder by binding parameters. assign a value to the placeholder through the Index Array $ arr = ['andy Lau ', '000000', 'mal', '53']; // send the pre-processing statement $ res = $ stmt-> execute ($ arr); PDO: transaction data table: MyISAM features: Fast execution efficiency does not support transaction InnoDB features: transaction Processing supported: 1. start beginTransaction () 2. commit transaction commit () 3. rollback transaction rollback () $ pdo-> beginTransaction ()

 

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.