PHPPDO-& gt; exec () execution of SQL statements without return result set _ PHP Tutorial

Source: Internet
Author: User
PHPPDO-& amp; gt; exec (): execute an SQL statement that does not return a result set. Does PHPPDO-exec () execute an SQL statement that does not return a result set? The php * DO-exec () method is mainly used for operations that DO not return result sets, such as INSERT, UPDATE, DELETE, and other operations. it returns php pdo-> 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 can contain no quotation marks $ SQL _exec = "INSER T into userlist (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']). "" ;}?>

The http://www.bkjia.com/PHPjc/1072631.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1072631.htmlTechArticlePHP PDO-exec () executes the SQL statement without returning the result set? Php/* DO-exec () method is mainly used for operations that DO not return result sets, such as INSERT, UPDATE, DELETE, etc. it returns...

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.