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