PHP PDO Learning (ii) EXEC Execute SQL

Source: Internet
Author: User

EXEC executes an SQL statement in a separate function call, returning the number of rows affected by this statement.

exec does not process the SELECT statement

<?PHPTry {    $pdo=NewPDO (' Mysql:host=localhost:3306;dbname=zhy ', ' root ', ' root '); $sql= <<<EOF CREATE TABLEIFNot EXISTS USERS (IDINTEGERAuto_incrementKEY,USERNAME VARCHAR () notNULLUNIQUE,PASSWORD CHAR (() notNULL,EMAIL VARCHAR (30) ) EOF; $res=$pdo-exec($sql); Var_dump($res); Echo' ; $sql= ' INSERT into USERS (USERNAME, PASSWORD, EMAIL) VALUES ("Zyn", "'.MD5(' Zyn '). ' "," [email protected] "); '; $res=$pdo-exec($sql); Echo' Number of records affected: '.$res.‘ <br/> '; Echo' The last inserted ID number is: '.$pdo-Lastinsertid ();//Var_dump ($res);    Echo' ;} Catch(pdoexception$e) {    Echo $e-getMessage ();}
<?PHPHeader(' Content-type:text/html;charset=utf-8 ');Try {    $pdo=NewPDO (' Mysql:host=localhost:3306;dbname=zhy ', ' root ', ' root '); $sql= ' UPDATE USERS SET USERNAME = ' ZHY3 ' WHERE id=1 '; $res=$pdo-exec($sql); Echo $res.‘ Records are affected ';} Catch(pdoexception$e) {    Echo $e-getMessage ();}

PHP PDO Learning (ii) EXEC Execute SQL

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.