Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在不更改max_allowed_数据包的情况下将大数据插入MySQL数据库_Php_Mysql_Pdo_Insert_Large Data - Fatal编程技术网

Php 如何在不更改max_allowed_数据包的情况下将大数据插入MySQL数据库

Php 如何在不更改max_allowed_数据包的情况下将大数据插入MySQL数据库,php,mysql,pdo,insert,large-data,Php,Mysql,Pdo,Insert,Large Data,我有一个大于max\u allowed\u packet(1MB)的文本 为什么我不能用下面的代码插入数据 $db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d'); $db->exec('SET NAMES utf8'); $stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)'); $tx = file_get_contents('./test

我有一个大于
max\u allowed\u packet
(1MB)的文本 为什么我不能用下面的代码插入数据

$db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d');

$db->exec('SET NAMES utf8');

$stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)');
$tx = file_get_contents('./test.html');
$stmt->bindParam(1, $tx, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
它说:
致命错误:无法通过引用传递参数1
,但我从以下位置复制代码: -

数据库结构:

CREATE TABLE `book`
(`text` mediumtext COLLATE utf8_unicode_ci NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
试着这样做:

$db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d');

$db->exec('SET NAMES utf8');

$stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)');

// note the "fopen" function, not file_get_contents
$tx = fopen('test.html', 'rb');
$stmt->bindParam(1, $tx, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
CREATE TABLE `book`
(`text` BLOB NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
另外,关于:

有人指出:

。。。将LOB绑定到名为$LOB的变量中,然后将其发送到 使用fpassthru()启动浏览器。因为LOB表示为 流,函数,如fgets()、fread()和stream_get_contents() 可以用在上面

另外,尝试将“文本”表字段更改为BLOB数据类型,如下所示:

$db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d');

$db->exec('SET NAMES utf8');

$stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)');

// note the "fopen" function, not file_get_contents
$tx = fopen('test.html', 'rb');
$stmt->bindParam(1, $tx, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
CREATE TABLE `book`
(`text` BLOB NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
试着这样做:

$db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d');

$db->exec('SET NAMES utf8');

$stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)');

// note the "fopen" function, not file_get_contents
$tx = fopen('test.html', 'rb');
$stmt->bindParam(1, $tx, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
CREATE TABLE `book`
(`text` BLOB NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
另外,关于:

有人指出:

。。。将LOB绑定到名为$LOB的变量中,然后将其发送到 使用fpassthru()启动浏览器。因为LOB表示为 流,函数,如fgets()、fread()和stream_get_contents() 可以用在上面

另外,尝试将“文本”表字段更改为BLOB数据类型,如下所示:

$db = new PDO('mysql:dbname=test;host=localhost', 'root', '5u4f1d');

$db->exec('SET NAMES utf8');

$stmt = $db->prepare('INSERT `book` (`text`) VALUES (?)');

// note the "fopen" function, not file_get_contents
$tx = fopen('test.html', 'rb');
$stmt->bindParam(1, $tx, PDO::PARAM_LOB);

$db->beginTransaction();
$stmt->execute();
$db->commit();
CREATE TABLE `book`
(`text` BLOB NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

文件\u get\u内容是否返回任何值或为空?@Zlatan是,它返回大文本。文件\u get\u内容是否返回任何值或为空?@Zlatan是,它返回大文本。否,它无法解决问题。您引用的关于
fpassthru
的内容是关于选择(读取)而不是插入是的,我试图解决
$tx=fopen('test.html','rb')的问题
而不是
$tx=file_get_contents('./test.html')但问题没有解决。表中的“文本”字段是“BLOB”数据类型,还是“文本”类型?我已更改了我的回答帖子。更改表格布局。。请将表格文本字段更改为BLOB,然后尝试该配置。。如果有效,请接受并评价我的答案:)谢谢!不,这不能解决问题。您引用的关于
fpassthru
的内容是关于选择(读取)而不是插入是的,我试图解决
$tx=fopen('test.html','rb')的问题
而不是
$tx=file_get_contents('./test.html')但问题没有解决。表中的“文本”字段是“BLOB”数据类型,还是“文本”类型?我已更改了我的回答帖子。更改表格布局。。请将表格文本字段更改为BLOB,然后尝试该配置。。如果有效,请接受并评价我的答案:)谢谢!