DML statement pre-compilation:
Mysqli:
<?php$mysqli = new Mysqli ("localhost", "root", "root", "dbname"), $mysqli->query ("Set names UTF8"); $sql = ' Insert into user (Id,name,age,email) VALUES (?,?,?,?) '; $mysqli _stmt = $mysqli->prepare ($sql); $id = 2; $name = ' Kung '; $age =; $email = ' [email protected] '; $mysqli _stmt->b Ind_param (' ISIS ', $id, $name, $age, $email); $res = $mysqli _stmt->execute (), if (! $res) {echo ' error '. $mysqli _stmt- >error;exit;} Else{echo ' OK ';} $id = 3; $name = ' Xiaoyu '; $age =; $email = ' [email protected] '; $mysqli _stmt->bind_param (' ISIS ', $id, $name, $age, $ email), $res = $mysqli _stmt->execute (), if (! $res) {echo ' error '. Mysqli_stmt->error;exit;} Else{echo ' OK ';}? >
Pdo:
<?php$dns = ' mysql:dbname=dbname;host=127.0.0.1 '; $user = ' root '; $password = ' root '; try{$pdo = new PDO ($dns, $user, $ password);} catch (Pdoexception $e) {echo $e->getmessage ();} $pdo->query ("Set names UTF8"); $sql = ' inser into user values (: id,:name,:age,:email) '; $pdo _stmt = $pdo->prepare ($ SQL); $id = 2; $name = ' Kung '; $age =; $email = ' [email protected] '; $pdo _stmt->bindparam (': Id ', $id); $pdo _stmt-> Bindparam (': Name ', $name), $pdo _stmt->bindparam (': Age ', $age) $pdo _stmt->bindparam (': email ', $email); $pdo _ Stmt->execute ();? >
DQL Statement pre-compilation:
Mysqli:
<?php$mysqli = new Mysqli ("localhost", "root", "root", "dbname"), $mysqli->query ("Set names UTF8"); $sql = "SELECT ID , name from user where ID >? "; $mysqli _stmt = $mysqli->prepare ($sql); $id = 1; $mysqli _stmt->bind_param (' i ', $id); $mysqli _stmt->bind_result ($id, $name); $mysqli _stmt->execute (); while ($mysqli _stmt->fetch ()) {echo $id. '--$name;} $mysqli _stmt->close (); $mysqli->close ();? >
MySQL pre-compilation processing (MYSQLI, PDO)