定义和用法
如果表的列之一是 BLOB 类型的 TEXT,则mysqli_stmt_send_long_data()函数用于将数据分块发送到该列。
您无法使用此函数关闭持久连接。
用法
mysqli_stmt_send_long_data($stmt);
参数
Sr.No | 参数及说明 |
---|---|
1 |
stmt(Mandatory) 这是一个表示准备好的语句的对象。 |
2 |
param_nr(Mandatory) 这是一个整数值,表示您需要将给定数据关联到的参数。 |
3 |
data(Mandatory) 这是一个字符串值,表示要发送的数据。 |
返回值
PHP mysqli_stmt_send_long_data() 函数返回一个布尔值,成功时为真,失败时为假。
PHP版本
这个函数最初是在 PHP 版本 5 中引入的,适用于所有后续版本。
示例
以下示例演示了 mysqli_stmt_send_long_data() 函数的用法(程序风格) -
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Creating a table
mysqli_query($con, "CREATE TABLE test(message BLOB)");
print("Table Created \n");
//Inserting data
$stmt = mysqli_prepare($con, "INSERT INTO test values(?)");
//Binding values to the parameter markers
mysqli_stmt_bind_param($stmt, "b", $txt);
$txt = NULL;
$data = "This is sample data";
mysqli_stmt_send_long_data($stmt, 0, $data);
print("Data Inserted");
//Executing the statement
mysqli_stmt_execute($stmt);
//Closing the statement
mysqli_stmt_close($stmt);
//Closing the connection
mysqli_close($con);
?>
这将产生以下结果 -
Table Created Data Inserted
执行上述程序后,测试表的内容如下 -
mysql> select * from test; +---------------------+ | message | +---------------------+ | This is sample data | +---------------------+ 1 row in set (0.00 sec)
示例
在面向对象风格中,这个函数的语法是 $stmt->send_long_data();以下是面向对象样式 $minus 中此函数的示例;
假设我们有一个名为 foo.txt 的文件,其中包含消息你好,欢迎来到 Tutorialspoint。
<?php
//Creating a connection
$con = new mysqli("localhost", "root", "password", "mydb");
//Creating a table
$con -> query("CREATE TABLE test(message BLOB)");
print("Table Created \n");
//Inserting values into the table using prepared statement
$stmt = $con -> prepare("INSERT INTO test values(?)");
//Binding values to the parameter markers
$txt = NULL;
$stmt->bind_param("b", $txt);
$fp = fopen("foo.txt", "r");
while (!feof($fp)) {
$stmt->send_long_data( 0, fread($fp, 8192));
}
print("Data Inserted");
fclose($fp);
//Executing the statement
$stmt->execute();
//Closing the statement
$stmt->close();
//Closing the connection
$con->close();
?>
这将产生以下结果 -
Table Created Data Inserted
执行上述程序后,测试表的内容如下 -
mysql> select * from test; +---------------------------------------------+ | message | +---------------------------------------------+ | Hello how are you welcome to Tutorialspoint | +---------------------------------------------+ 1 row in set (0.00 sec)
相关用法
- PHP mysqli_stmt_store_result()用法及代码示例
- PHP mysqli_stmt_sqlstate()用法及代码示例
- PHP mysqli_stmt_affected_rows()用法及代码示例
- PHP mysqli_stmt_fetch()用法及代码示例
- PHP mysqli_stmt_data_seek()用法及代码示例
- PHP mysqli_stmt_free_result()用法及代码示例
- PHP mysqli_stmt_error()用法及代码示例
- PHP mysqli_stmt_field_count()用法及代码示例
- PHP mysqli_stmt_errno()用法及代码示例
- PHP mysqli_stmt_get_result()用法及代码示例
- PHP mysqli_stmt_init()用法及代码示例
- PHP mysqli_stmt_bind_result()用法及代码示例
- PHP mysqli_stmt_reset()用法及代码示例
- PHP mysqli_stmt_attr_get()用法及代码示例
- PHP mysqli_stmt_param_count()用法及代码示例
- PHP mysqli_stmt_attr_set()用法及代码示例
- PHP mysqli_stmt_prepare()用法及代码示例
- PHP mysqli_stmt_bind_param()用法及代码示例
- PHP mysqli_stmt_close()用法及代码示例
- PHP mysqli_stmt_num_rows()用法及代码示例
注:本文由纯净天空筛选整理自 PHP mysqli_stmt_send_long_data() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。