<? PHP/** operations on the PDO database **/$ DNS = "MYSQL: dbname = BBS; host = localhost"; $ user = "root"; $ Password = ""; $ opt = array (PDO: attr_persistent => true); $ PDO = new PDO ($ DNS, $ user, $ password, $ OPT);/** getattribute () view Database Connection Properties **/var_dump ("Disable Automatic submission function :". $ PdO-> getattribute (PDO: attr_autocommit); var_dump ("the mode in which PDO errors are handled :". $ PdO-> getattribute (PDO: attr_errmode); var_dump ("case-sensitive conversion of table field characters :". $ PdO-> getattribute (PDO: attr_case); var_dump ("special information related to the connection status :". $ PdO-> getattribute (PDO: attr_connection_status); var_dump ("convert an empty string to a SQL NULL :". $ PdO-> getattribute (PDO: attr_oracle_nulls); var_dump ("Application Program Get data size in advance :". $ PdO-> getattribute (PDO: attr_persistent); var_dump ("server information unique to the database :". $ PdO-> getattribute (PDO: attr_server_info); var_dump ("Database Server version :". $ PdO-> getattribute (PDO: attr_server_version); var_dump ("database Client Version :". $ PdO-> getattribute (PDO: attr_client_version);/** two execution methods: * Exec: return the number of affected rows for insert Delete update * query, and return a pdostatement, operations on each piece of information ** // ** $ SQL = "delete from news where id = 16"; Echo $ PdO-> exec ($ SQL ); ------------------------------------------------ quote for SQL statements escape $ SQL = $ PdO-> quote ("delete from news where id = '1'"); echo $ SQL; // output: 'delete from news where id = \ '1 \ ''' -------------------------------------------------- lastinsertid $ SQL = "insert into news values ('', 'Boy ', 'Boy ')"; $ PdO-> exec ($ SQL); echo "ID of the inserted record :". $ PdO-> lastinsertid (); // obtain the ID of the last inserted record ------------------------ -------------------------- One of the most important methods is prepare ($ SQL), which returns a pdostatement. Similarly, another method for returning pdostatement is query () used to query data prepare ($ SQL) is to pre-process SQL statements and return a pdostatement object, it contains a lot of useful methods. Next section record the pdostatement attribute and legal -------------------------------------------------- The following is the transaction operation ***/$ sql1 = "delete from news where id = 21 "; $ sql2 = "delete from news where id = 22"; $ PdO-> setattribute (PDO: attr_errmode, PDO: errmode_mode t Ion); try {$ PdO-> begintransaction (); $ PdO-> exec ($ sql1); $ PdO-> exec ($ sql2);} catch (exception $ ex) {$ PdO-> rollback (); echo "database operation failed ". $ ex-> getmessage () ;}?>