The mysqli preprocessing involves several functions:
Mysqli_stmt Mysqli_prepare (mysqli $link, string $query) bool Mysqli_stmt_bind_param (mysqli_stmt $stmt, String $types , Mixed & $var 1 [, Mixed &$ ...] BOOL Mysqli_stmt_execute (mysqli_stmt $stmt) bool Mysqli_stmt_close (mysqli_stmt $stmt) mixed mysqli_query (mysqli $lin K, string $query) bool Mysqli_set_charset (mysqli $link, String $charset)
< Span class= "Methodparam" > < Span class= "Methodparam" > The specific sample code is as follows:
<?php $conn =mysqli_connect ("localhost", "root", "root", "test"),//sets the character set Mysqli_set_charset ($conn, "UTF8");//preprocessing, Note the type of return is Mysqli_stmt$stmt=mysqli_prepare ($conn, "insert into AAA values (?,?)"); /binding parameters, the second parameter, see note below//notice, in the $id, $name the position of variables, cannot appear on the solid//Mysqli_stmt_bind_param ($stmt, "is", 5, ' aaaaa '); the notation is wrong mysqli_stmt _bind_param ($stmt, "is", $id, $name);//Parameter Assignment $id= "Close"; $name = "xxxxxx";//Perform preprocessing mysqli_stmt_execute ($stmt);//shutdown preprocessing,// Note that the shutdown is not a database connection, but rather a "preprocessing" mysqli_stmt_close ($stmt);//Close database connection Mysqli_close ($conn);?>
When you pay attention to the binding parameters,
BOOL Mysqli_stmt_bind_param (mysqli_stmt $stmt, String $types, Mixed & $var 1 [, Mixed &$ ...]
The second parameter is type (type), with 4 types, namely:
I (integer integer),
D (double-precision floating-point number double),
S (Strings string),
B (Binary large data block blob)
Each type, that is, each letter (i/d/s/b) corresponds to a parameter, the position of each parameter corresponds to the correct type, the order is not reversed
Mysqli---Preprocessing for process practice