English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
mysqli_stmt_send_long_data()函数分块发送数据。
如果表的某一列是BLOB类型的TEXT,则该mysqli_stmt_send_long_data()函数用于将数据分块发送到该列。
您不能使用此函数关闭持久连接.
mysqli_stmt_send_long_data($stmt);
序号 | 参数及说明 |
---|---|
1 | stmt(必需) 这是表示准备好的语句的对象。 |
2 | param_nr(必需) 这是一个整数值,表示您需要将给定数据关联到的参数。 |
3 | data(必需) 这是一个字符串值,表示要发送的数据。 |
PHP mysqli_stmt_send_long_data()函数返回一个布尔值,成功时为true,失败时为false.
此函数最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_stmt_send_long_data()函数的用法(面向过程风格)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Create table mysqli_query($con, "CREATE TABLE test(message BLOB)"); print("Create table \n"); //Insert data $stmt = mysqli_prepare($con, "INSERT INTO test values(?)"); //Bind value to parameter marker mysqli_stmt_bind_param($stmt, "b", $txt); $txt = NULL; $data = "This is sample data"; mysqli_stmt_send_long_data($stmt, 0, $data); print("Insert data"); //Execute statement mysqli_stmt_execute($stmt); //End statement mysqli_stmt_close($stmt); //Close connection mysqli_close($con); ?>
Output result
Create table Insert data
After executing the above program,TestTable content as follows:
mysql> select * from test; +---------------------+ | message | +---------------------+ | This is sample data | +---------------------+ 1 row in set (0.00 sec)
In object-oriented style, the syntax of this function is$stmt-> send_long_data();.Here is an example of this function in object-oriented style;
Suppose we have a namedfoo.txtof the file,Content is "Hello how are you welcome to oldtoolbag.com”.
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "mydb"); //Create table $con -> query("CREATE TABLE test(message BLOB)"); print("Create table \n"); //Insert values into the table using prepared statements $stmt = $con -> prepare("INSERT INTO test values(?)"); //Bind value to parameter marker $txt = NULL; $stmt-> bind_param("b", $txt); $fp = fopen("foo.txt", "r"); while (!feof($fp)) { $stmt-> send_long_data( 0, fread($fp, 8192)); } print("Insert data"); fclose($fp); //Execute statement $stmt-> execute(); //End statement $stmt-> close(); //Close connection $con-> close(); ?>
Output result
Create table Insert data
After executing the above program,TestTable content as follows:
mysql> select * from test; +---------------------------------------------+ | message | +---------------------------------------------+ | Hello how are you welcome to oldtoolbag.com | +---------------------------------------------+ 1 row in set (0.00 sec)