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 ...