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 ()