array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.pg-unescape-bytea.php', 1 => 'pg_unescape_bytea', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 函数', ), 'prev' => array ( 0 => 'function.pg-tty.php', 1 => 'pg_tty', ), 'next' => array ( 0 => 'function.pg-untrace.php', 1 => 'pg_untrace', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/pgsql/functions/pg-unescape-bytea.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_unescape_bytea — 反转义 bytea 类型的二进制数据
pg_unescape_bytea() 反转义 PostgreSQL bytea 数据值。返回反转义后的字符串,可能包含二进制数据。
注意:
当
SELECT
bytea 类型时,PostgreSQL 返回前缀为“\”的八进制字节值(例如 \032)。用户需要手动将其转换回二进制格式。本函数需要 PostgreSQL 7.2 及其以后的版本。在 PostgreSQL 7.2.0 和 7.2.1 中,当启用了多字节支持时 bytea 值必需进行类型转换,例如
INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea);
;PostgreSQL 7.2.2 及其以后的版本不需要类型转换。唯一的例外是当客户端和后端的字符编码不匹配时,有可能出现多字节流错误。用户必须将其转换为 bytea 来避免此错误。
包含反转义数据的 string。
示例 #1 pg_unescape_bytea() 示例
<?php
// Connect to the database
$dbconn = pg_connect('dbname=foo');
// Get the bytea data
$res = pg_query("SELECT data FROM gallery WHERE name='Pine trees'");
$raw = pg_fetch_result($res, 'data');
// Convert to binary and send to the browser
header('Content-type: image/jpeg');
echo pg_unescape_bytea($raw);
?>