English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_stmt_send_long_data() Function Usage and Example

PHP MySQLi Reference Manual

mysqli_stmt_send_long_data() function sends data in chunks.

Definition and Usage

If a column in the table is of BLOB type TEXT, then thismysqli_stmt_send_long_data()The function is used to send data in chunks to the column.

You cannot use this function to closePersistent Connection

Syntax

mysqli_stmt_send_long_data($stmt);

Parameter

Serial NumberParameters and Description
1

stmt (required)

This is the object representing the prepared statement.

2

param_nr (required)

This is an integer value representing the parameter to which the given data is to be associated.

3

data (required)

This is a string value representing the data to be sent.

Return Value

The PHP mysqli_stmt_send_long_data() function returns a boolean value, which is true when the operation is successful.true, and is false when the operation fails.false

PHP Version

This function was initially introduced in PHP version5introduced and can be used in all higher versions.

在线示例

The following example demonstratesmysqli_stmt_send_long_data()Function Usage (Procedural Style)-

输出结果

创建表
插入数据

执行完上述程序后,测试表的内容如下:

mysql> select * from test;
+---------------------+
| message             |
+---------------------+
| This is sample data |
+---------------------+
1 row in set (0.00 sec)

在线示例

在面向对象风格中,此函数的语法为$stmt-> send_long_data();。以下是面向对象风格中此函数的示例;

假设我们有一个名为foo.txt的文件,内容为“Hello how are you welcome to oldtoolbag.com”

 query("CREATE TABLE test(message BLOB)");
   print("创建表 \n");
   //使用预准备语句将值插入到表中
   $stmt = $con -> prepare("INSERT INTO test values(?)");
   //将值绑定到参数标记
   $txt = NULL;
   $stmt->bind_param("b", $txt);
   $fp = fopen("foo.txt", "r");
   while (!feof($fp)) {
      $stmt->send_long_data( 0, fread($fp, 8192));
   }
   print("插入数据");
   fclose($fp);
   //执行语句
   $stmt->execute();
   //结束语句
   $stmt->close();
   //关闭连接
   $con->close();
?>

输出结果

创建表
插入数据

执行完上述程序后,测试表的内容如下:

mysql> select * from test;
+---------------------------------------------+
| message                                     |
+---------------------------------------------+
| Hello how are you welcome to oldtoolbag.com |
+---------------------------------------------+
1 row in set (0.00 sec)

PHP MySQLi Reference Manual