English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP MySQLi Референсный руководств
The mysqli_stmt_send_long_data() function sends data in chunks.
If one of the columns in the table is 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.
mysqli_stmt_send_long_data($stmt);
Serial number | Parameters and descriptions |
---|---|
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 needs to be associated. |
3 | data (required) This is a string value representing the data to be sent. |
The PHP mysqli_stmt_send_long_data() function returns a boolean value, true when successful.true, when it fails isfalse.
This function was initially introduced in PHP version 5 and can be used in all higher versions.
The following examples demonstratemysqli_stmt_send_long_data()Function usage (procedural style)-
<?php //Установление подключения $con = mysqli_connect("localhost", "root", "password", "mydb"); //Создание таблицы mysqli_query($con, "CREATE TABLE test(message BLOB)"); print("создание таблицы "); // Insert data $stmt = mysqli_prepare($con, "INSERT INTO test values(?)"); //Привязка значения к маркеру параметра mysqli_stmt_bind_param($stmt, "b", $txt); $txt = NULL; $data = "This is sample data"; mysqli_stmt_send_long_data($stmt, 0, $data); print("вставка данных"); //Выполнение инструкции mysqli_stmt_execute($stmt); //Закрытие инструкции mysqli_stmt_close($stmt); //Закрытие подключения mysqli_close($con); ?>
вывод результатов
создание таблицы вставка данных
После выполнения вышеуказанного кода:тестСодержание таблицы следующим образом:
mysql> select * from test; +---------------------+ | message | +---------------------+ | Это образец данных | +---------------------+ 1 строка в наборе (0.00 сек)
В стилистике面向 объектов синтаксис этой функции такой:$stmt-> send_long_data();。Вот пример этой функции в стилистике面向对象的 программирования;
предположим, что у нас есть таблица с именемfoo.txtфайлсодержание файла "Привет как ты приветствуем на oldtoolbag.com".
<?php //Установление подключения $con = new mysqli("localhost", "root", "password", "mydb"); //Создание таблицы $con->query("CREATE TABLE test(message BLOB)"); print("создание таблицы "); //Использование предподготовленной инструкции для вставки значений в таблицу $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; +---------------------------------------------+ | сообщение | +---------------------------------------------+ | Привет как ты приветствуем на oldtoolbag.com | +---------------------------------------------+ 1 строка в наборе (0.00 сек)