1 |
Application environment |
|
|
|
Mysqli preprocessing function (used in large amount of data processing) |
2 |
Steps |
|
|
A) Mysqli connection database |
$mysqli = new mysqli (' localhost ', ' root ', ' root ', ' Chuanzhi '); |
|
b) Set the encoding |
$mysqli->set_charset (' gb2312 '); |
|
c) Send query statement |
Using $mysqli->prepare ($query) This method means preprocessing, and if a value is involved, the query field must be specified $query = "Select Id,proname,proclass,proprice from product where id>?"; $stmt = $mysqli->prepare ($query); |
|
d) Provision of conditions |
Like the last sentence? As an indeterminate value, you need to specify $stmt->bind_param (' i ', $id); With variable bindings? The value represented, I denotes an integer, D is a float, B is binary, and s represents all other $id = ' 1 '; Specifying the value of a variable $stmt->execute (); Send a variable, the server statement is now complete |
|
e) retrieving results from SQL Server |
The preprocessing statement saves the result set in the SQL Open memory, and PHP's memory cannot be used directly (count is a PHP function, not an SQL function, cannot directly interact with SQL memory), and by default every fetch () takes a row out of SQL memory. However, you cannot get the number of rows without using Store_result (). Of course, if you have only one line of results, you can ignore this sentence. Keep in mind that fetching data in mysqli preprocessing can only be done with fetch () because the Mysqli_stmt class has no other value method $stmt->store_result ();//If the variable is received, it will be found to be successful display 1, otherwise display 0 |
|
f) Get the number of result set rows |
$count = $stmt->num_rows (); |
|
g) fields to be output for binding result sets |
$stmt->bind_result ($id, $proName, $proClass, $proPrice); The name does not matter, anyway, in order to match the query field, the number of variables to match the number of query fields |
|
h) Output Results |
As I said earlier, since we are going to take a value, of course, the preceding query specifies the queried field, the variable of the previous sentence is used |
|
I |
You know, close the mysqli link. |