Core approach
$mysqli _stmt = Mysqli->prepare ($sql); Preprocessing, returning the statement object
$mysqli _stmt->bind_param (); Binding parameters, type correspondence are as follows:
I:integer
S:string
D:double
B:blob
$mysqli _stmt->excute (); Execute SQL
<?PHP$mysqli= @NewMysqli ("localhost:3306", "root", "root", "Zhy");if($mysqli-Connect_errno) { die("MYSQL CONNECT ERROR:".)$mysqli-connect_error);}$mysqli->set_charset (' UTF8 ');$sql= ' INSERT into user (name, age, description) VALUES (?,?,?) ';$mysqli _stmt=$mysqli->prepare ($sql);//Print_r ($mysqli _stmt); for($i= 0;$i< 5;$i++) { $name= ' Prepare '.$i; $age= 25 +$i; $description= ' description '.$i; $mysqli _stmt->bind_param (' sis ',$name,$age,$description); if($mysqli _stmt-Execute ()) { Echo $mysqli _stmt-insert_id; Echo' <br/> '; } Else { Echo $mysqli _stmt-error; }}
PHP Mysqli Learning (v) preprocessing