PHP5 mysqli Binding Parameters

Source: Internet
Author: User
Tags php script


The so-called binding parameter is to bind a custom variable in a PHP script to a parameter in an SQL statement (parameter use "?). instead), the binding parameter uses the Bind_param () method, which has the following syntax format:

BOOL Bind_param (String $types, Mixed & $var 1 [, Mixed &$ ...]

The parameters involved in the above syntax are described below.


Types: The data type of the bound variable, which accepts 4 character types, as shown in the table:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6B/67/wKiom1UskHbw9E7yAACRo1iRQzs193.jpg "title=" QQ picture 20150414120324.png "alt=" Wkiom1uskhbw9e7yaacro1irqzs193.jpg "/>


VAR1: The number of bound variables must be consistent with the number of parameters in the SQL statement

<?php$mysqli=new mysqli ("localhost", "root", "root", "Sunyang");//Instantiate mysqli$query= "INSERT into employee (EMP_ Number,emp_name,emp_age) VALUES (?,?,?) "; $result = $mysqli->prepare ($query) $result->bind_param ("SSI", $number, $name, $age);//binding parameter $number= ' sy0807 '; $ Name= ' Employee7 '; $age =20; $result->execute ();//execute pre-prepared statement $result->close (); $mysqli->close (); >



PHP5 mysqli Detailed usage tutorial see:

http://blog.sina.com.cn/s/blog_71655d710100tjwf.html






The difference between MySQL and mysqli:


1, MySQL is a non-holding connection function, MySQL each link will open a connected process.


2, Mysqli is the permanent connection function, mysqli multiple runs mysqli will use the same connection process, thereby reducing the server overhead. Mysqli encapsulates some of the advanced operations, such as transactions, while encapsulating many of the methods available in the DB operation process.




This article is from "Phper Xuchen-Focus on PHP Technology" blog, be sure to keep this source http://xuqin.blog.51cto.com/5183168/1632184

PHP5 mysqli Binding Parameters

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.