2

(1MB)より大きいテキストがあるのにmax_allowed_packet、以下のコードでデータを挿入できないのはなぜですか?

$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();

それは言う:Fatal error: Cannot pass parameter 1 by reference、しかし私はからコードをコピーします:-http ://www.php.net/manual/en/pdo.lobs.php

db struct:

CREATE TABLE `book`
(`text` mediumtext COLLATE utf8_unicode_ci NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4

1 に答える 1

0

このようにしてみてください:

$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();

また、

次のことが指摘されています。

... LOB を $lob という名前の変数にバインドし、fpassthru() を使用してブラウザーに送信します。LOB はストリームとして表現されるため、fgets()、fread()、stream_get_contents() などの関数を使用できます。

また、次のように「テキスト」テーブル フィールドを BLOB データ型に変更してみてください。

CREATE TABLE `book`
(`text` BLOB NOT NULL)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
于 2012-10-15T15:32:56.143 に答える