SQLite3::openBlob
(PHP 5 >= 5.3.0, PHP 7)
SQLite3::openBlob - 打开一个流资源来读取一个BLOB
描述
public resource SQLite3::openBlob ( string $table , string $column , int $rowid [, string $dbname = "main" [, int $flags = SQLITE3_OPEN_READONLY ]] )
打开流资源以读取或写入BLOB,该BLOB将通过以下方式进行选择:
选择column
从dbname . table
WHERE rowid =rowid
注意:通过写入流不可能改变BLOB的大小。相反,必须执行UPDATE语句,可能使用SQLite的zeroblob()函数来设置所需的BLOB大小。
参数
table
表名。
column
列名称。
rowid
行ID。
dbname
数据库的符号名称
flags
无论是SQLITE3_OPEN_READONLY
或SQLITE3_OPEN_READWRITE
打开流只读,或分别打开阅读和写作。
返回值
返回流资源,或者失败返回FALSE
。
Changelog
版 | 描述 |
---|---|
7.2.0 | flags参数已添加,允许写入BLOB; 以前只有阅读得到支持。 |
示例
Example #1 SQLite3::openBlob() example
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES ('Lorem ipsum')");
$stream = $conn->openBlob('test', 'text', 1);
echo stream_get_contents($stream);
fclose($stream); // mandatory, otherwise the next line would fail
$conn->close();
?>
上面的例子将输出:
Lorem ipsum
Example #2 Incrementally writing a BLOB
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES (zeroblob(36))");
$stream = $conn->openBlob('test', 'text', 1, 'main', SQLITE3_OPEN_READWRITE);
for ($i = 0; $i < 3; $i++) {
fwrite($stream, "Lorem ipsum\n");
}
fclose($stream);
echo $conn->querySingle("SELECT text FROM test");
$conn->close();
?>
上面的例子将输出:
Lorem ipsum
Lorem ipsum
Lorem ipsum
SQLite3::prepare →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com