MYSQLI---preprocessing for process practice

Source: Internet
Author: User
Tags stmt

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.