PHP pdo->exec () executes SQL statements with no return result set _php tutorial

Source: Internet
Author: User

PHP Pdo->exec () executes an SQL statement with no return result set


 The exec () method is primarily for operations returned without a result set, such as inserts, UPDATE, DELETE, and so on, which returns the number of columns that the current operation affects: Pdo->exec (String statement) *//Fabric PDO Connection    Header ("Content-type:text/html;charset=utf-8");    $DBH = "Mysql:host=localhost;dbname=test";    $db = new PDO ($dbh, ' root ', ' 123456 ');    $db->query ("Set character set ' UTF8 '");    Write Data $username = "Liming";       $password = MD5 ("123456"); $regdate = time ();//Returns an integer, so the following statement can be without quotation marks $sql _exec = "INSERT into userlist (username,password,regdate) VALUES (' $usern    Ame ', ' $password ', $regdate) ";    $count = $db->exec ($sql _exec); Echo ' write '. $count. ' Data record!     '; echo "
 
  
 ";    $sql _select = "SELECT * from UserList"; $sth = $db->query ($sql _select);//$STH is the result set object//$sth->setfetchmode (PDO::FETCH_ASSOC);//If not Setfetchmode ()    You can also set the while ($row = $sth->fetch (PDO::FETCH_ASSOC)) {Print_r ($row) by using the Fetch () method alone, as specified in the returned result type.    echo "Username:" $row [' username ']. "";    echo "Password:". $row [' Password ']. "";    echo "Registration time:". Date ("y-m-d", $row [' regdate ']). ""; }?>

http://www.bkjia.com/PHPjc/1072631.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072631.html techarticle PHP pdo-exec () executes an SQL statement with no result set returned? The Php/*do-exec () method is primarily for operations that do not have a result set, such as INSERT, UPDATE, DELETE, and so on, which 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.