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;
另外,关于:
$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;
另外,关于:
$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,然后尝试该配置。。如果有效,请接受并评价我的答案:)谢谢!