mysqli_stmt send_long_data() Method
The mysqli_stmt::send_long_data() / mysqli_stmt_send_long_data() function allows to send data parameter to the server in pieces (or chunks), for example - if the size of a blob exceeds the size of max_allowed_packet. This function can be called multiple times to send the parts of a character or binary data value for a column, which must be one of the TEXT or BLOB datatypes.
Syntax
//Object-oriented style public mysqli_stmt::bind_param(param_num, data) //Procedural style mysqli_stmt_bind_param(statement, param_num, data)
Parameters
statement |
Required. For procedural style only: Specify a mysqli_stmt object returned by mysqli_stmt_init(). |
param_num |
Required. Specify which parameter to associate the data with. Parameters are numbered beginning with 0. |
data |
Required. Specify a string containing data to be sent. |
Return Value
Returns true on success or false on failure.
Example: Object-oriented style
The example below shows the usage of mysqli_stmt::bind_param() method.
<?php //establishing connection to the database $mysqli = new mysqli("localhost", "user", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: ". $mysqli->connect_error; exit(); } $stmt = $mysqli>prepare("INSERT INTO messages (message) VALUES (?)"); $null = NULL; $stmt>bind_param("b", $null); $fp = fopen("messages.txt", "r"); while (!feof($fp)) { $stmt>send_long_data(0, fread($fp, 8192)); } fclose($fp); //executing the SQL statement $stmt->execute(); //closing the connection $mysqli->close(); ?>
Example: Procedural style
The example below shows the usage of mysqli_stmt_bind_param() function.
<?php //establishing connection to the database $mysqli = mysqli_connect("localhost", "user", "password", "database"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: ". mysqli_connect_error(); exit(); } $stmt = mysqli_prepare($mysqli, "INSERT INTO messages (message) VALUES (?)"); $null = NULL; mysqli_stmt_bind_param($stmt, "b", $null); $fp = fopen("messages.txt", "r"); while (!feof($fp)) { mysqli_stmt_send_long_data($stmt, 0, fread($fp, 8192)); } fclose($fp); //executing the SQL statement mysqli_stmt_execute($stmt); //closing the connection mysqli_close($mysqli); ?>
❮ MySQLi Functions Reference