PostgreSQL 9.0 introduced "hex" as the new default format for encoding binary data. Because "pg_unescape_bytea" only works with the old "escape" format, you need to do pg_query('SET bytea_output = "escape";'); before executing your select queries.
More details can be found here: http://www.postgresql.org/docs/9.0/static/datatype-binary.html
[Ed: Recent PostgreSQL versions support unescaping the "hex" format.]pg_unescape_bytea
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
pg_unescape_bytea
Референца за `function.pg-unescape-bytea.php` со подобрена типографија и навигација.
pg_unescape_bytea
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_unescape_bytea — Отстрани ескејп од бинарни податоци за bytea тип
= NULL
pg_unescape_bytea() отстранува ескејп од вредностите на PostgreSQL bytea податоците. Враќа стринг без ескејп, кој може да содржи бинарни податоци.
Забелешка:
избегнува низа за bytea тип. Враќа избегната низа.
SELECTКога вие
Параметри
string-
А string што содржи PostgreSQL bytea податоци за конвертирање во PHP бинарен стринг.
Вратени вредности
А string што ги содржи податоците без ескејп.
Примери
Пример #1 pg_unescape_bytea() example
<?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);
?>Види Исто така
- pg_escape_bytea() - Избегај низа за вметнување во bytea поле
- pg_escape_string() - Избегнувај идентификатор за вметнување во текстуално поле
Белешки од корисници 2 забелешки
The workaround is to configure a property in the postgres database for the user, to make postgres behave as the old default.
ALTER USER username SET bytea_output = 'escape';
(or using the pgadmin interface)