PHP mysqli_ stmt_ bind_ Param mysqli function


Definition and Usage

mysqli_stmt_bind_param– bind variables to prepared statements as parameters

Version support

I won’t support it support support


mysqli_stmt_bind_param ( mysqli_stmt $stmt , string $types , mixed &$var1 [, mixed &$... ] )

Pass to mysqli_ In the SQL statement of prepare(), bind variables for parameter markers.

be careful: if the data size of the variable exceeds the maximum value. If the packet size (max) is allowed_ allowed_ Packet), you must specify B in the type and use themysqli_stmt_send_long_data()Send data in packets.

be careful: willmysqli_stmt_bind_param()Andcall_user_func_array()Care must be taken when used in combination. Please note that,mysqli_stmt_bind_param()Requires parameters to be passed by reference, andcall_user_func_array()You can accept a list of variables that can represent references or values as parameters.


parameter Required describe
stmt yes By mysqli_ stmt_ The statement ID returned by init().
types yes A string containing one or more characters that specify the type of the corresponding bound variable:

  • i– the corresponding variable has an integer type
  • d– the type of the corresponding variable is double
  • s– the corresponding variable has a string type
  • b– the corresponding variable is blob, which will be sent as a packet
var1 yes The number of variables and the length of the string type must match the parameters in the statement.
No, depending on types, whether there are variables that need to be bound More variables

Return value

Returns true on success or false on failure.


<?php $link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
/* check connection */
if (!$link) {
   printf("Connect failed: %s\n", mysqli_connect_error());
$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
/* execute prepared statement */
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
/* close statement and connection */
/* Clean up table CountryLanguage */
mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");
printf("%d Row deleted.\n", mysqli_affected_rows($link));
/* close connection */

correlation function

mysqli_ stmt_ bind_ Result () – bind variables to prepared statements to store results
mysqli_ stmt_ Execute () – execute the prepared query
mysqli_ stmt_ Fetch () – get the result from the prepared statement into the bound variable
mysqli_ Prepare () – prepare to execute an SQL statement
mysqli_ stmt_ send_ long_ Data () – block sending data
mysqli_ stmt_ Errno () – returns the error code of the most recent statement call
mysqli_ stmt_ Error () – returns the string description of the last statement error


Recommended Today

WinForm DataGridView usage

//Method one: header exchange, background call this.dataGridView1.Columns[“ProductName”].DisplayIndex = 0;   //Method 2: header exchange, property setting, drag and drop on the page this.dataGridView1.AllowUserToOrderColumns = true;   //3. The time control is empty by default public WeighRecord() { InitializeComponent(); this.RecordTimepx.Format = DateTimePickerFormat.Custom; this.RecordTimepx.CustomFormat = ” “; } private void RecordTimepx_ValueChanged(object sender, EventArgs e) { this.RecordTimepx.Format = […]