php - 无法将长数据发送到 mysql MEDIUMTEXT 或 MEDIUMBLOB

标签 php mysql

我只能在字符串包含 523264 个字符时发送数据。帮助!

include("conn.php");

$stmt = $conn->prepare("INSERT INTO json_t (json_string) VALUES (?)");
$null = NULL;
$stmt->bind_param("b",$null);

$stmt->send_long_data(0, $json_to_save);

$stmt->execute();
$stmt->close();
$conn->close();

我试过了,还是一样的错误

"Error executing prepared statement. Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline."

请帮助。

$stmt = $conn->prepare("INSERT INTO json_t (json_string) VALUES (?)");
$null = NULL;
$stmt->bind_param("b",$null);

$max_allowed_packet = 100000;
if (!$stmt->bind_param('b', $null))
die("Error binding parameters. {$stmt->error}\n");
echo "<br/><br/>";
foreach(str_split($v, $max_allowed_packet) as $packet )
if (!$stmt->send_long_data(0, $packet))
die("Error sending long packet. {$stmt->error}\n");
echo "<br/><br/>";
if (!$stmt->execute())
die("Error executing prepared statement. {$stmt->error}\n");

好的,问题解决了。我将引擎更改为 MyISAM。

最佳答案

Allows to send parameter data to the server in pieces (or chunks), e.g. 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.

强调我的。

您需要自己分解字符串,例如使用 str_split($json_to_save, 100000);,然后调用 send_long_data 将每个片段作为 block 发送到MySQL 服务器。

关于php - 无法将长数据发送到 mysql MEDIUMTEXT 或 MEDIUMBLOB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36154227/

相关文章:

php - 客户端处理与服务器端处理,哪个快?

PHP Sleep 和 mysql 相处不好

mysql - MySql 中的动态列显示时差

php - 使用 PHP 从 SQL 查询创建一个没有重复行的 HTML 表?

php - 如何使用pecl solr扩展连接到mysql?

php - 需要修改base64

php - ubuntu 上的 apache2 - php 文件下载

php - 物理删除在 laravel5 中启用软删除的模型?

php - Mysql 查询另一个表上的计数

php - 如何通过 php/mysqli 获取行号