PHPPDO-& gt; exec (): execute an SQL statement that does not return a result set.
The exec () method is mainly used for operations that do not return result sets, such as INSERT, UPDATE, DELETE, and so on. The Returned result is the number of columns affected by the current operation syntax: PDO-> exec (string statement) * // Construct the PDO connection header ("Content-type: text/html; charset = utf-8"); $ dbh = "mysql: host = localhost; dbname = test "; $ db = new PDO ($ dbh, 'root', '123 '); $ db-> query ("set character set 'utf8'"); // write data $ username = "liming"; $ password = md5 ("123456 "); $ regdate = time (); // The Returned result is an integer. Therefore, the following statement may not contain quotation marks $ SQL _exec = "INSERT INTO user List (username, password, regdate) VALUES ('$ username',' $ password', $ regdate) "; $ count = $ db-> exec ($ SQL _exec ); echo 'write '. $ count. 'data record! '; Echo"
"; $ SQL _select =" SELECT * FROM userlist "; $…… = $ db-> query ($ SQL _select ); // $ something is the result set object // $ TH-> setFetchMode (PDO: FETCH_ASSOC); // if the returned result type is not specified in setFetchMode, you can also use the fetch () method to set while ($ row = $ Something-> fetch (PDO: FETCH_ASSOC) {print_r ($ row); echo "username :". $ row ['username']. ""; echo "password :". $ row ['password']. ""; echo "registration time :". date ("Y-m-d", $ row ['regdate']). "" ;}?>