<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Unescape binary for bytea type</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-tty.html">pg_tty</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-untrace.html">pg_untrace</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.pg-unescape-bytea" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_unescape_bytea</h1> <p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_unescape_bytea</span> — <span class="dc-title"> Unescape binary for bytea type </span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-unescape-bytea-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>pg_unescape_bytea</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_unescape_bytea()</strong></span> unescapes PostgreSQL bytea data values. It returns the unescaped string, possibly containing binary data. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> When you <em>SELECT</em> a bytea type, PostgreSQL returns octal byte values prefixed with '\' (e.g. \032). Users are supposed to convert back to binary format manually. </p> <p class="para"> This function requires PostgreSQL 7.2 or later. With PostgreSQL 7.2.0 and 7.2.1, bytea values must be cast when you enable multi-byte support. i.e. <em>INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea);</em> PostgreSQL 7.2.2 or later does not need a cast. The exception is when the client and backend character encoding does not match, and there may be multi-byte stream error. User must then cast to bytea to avoid this error. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.pg-unescape-bytea-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">data</code></em></span> <dd> <p class="para"> A <span class="type"><a href="language.types.string.html" class="type string">string</a></span> containing PostgreSQL bytea data to be converted into a PHP binary string. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-unescape-bytea-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> A <span class="type"><a href="language.types.string.html" class="type string">string</a></span> containing the unescaped data. </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-unescape-bytea-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2126"> <p><strong>Example #1 <span class="function"><strong>pg_unescape_bytea()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php <br /> </span><span style="color: #FF8000">// Connect to the database<br /> </span><span style="color: #0000BB">$dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'dbname=foo'</span><span style="color: #007700">);<br /> <br /> </span><span style="color: #FF8000">// Get the bytea data<br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT data FROM gallery WHERE name='Pine trees'"</span><span style="color: #007700">); <br /> </span><span style="color: #0000BB">$raw </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_fetch_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #DD0000">'data'</span><span style="color: #007700">);<br /> <br /> </span><span style="color: #FF8000">// Convert to binary and send to the browser<br /> </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type: image/jpeg'</span><span style="color: #007700">);<br /> echo </span><span style="color: #0000BB">pg_unescape_bytea</span><span style="color: #007700">(</span><span style="color: #0000BB">$raw</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-function.pg-unescape-bytea-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.5.1</td> <td> A warning is thrown if the input string is invalid. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-unescape-bytea-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pg-escape-bytea.html" class="function" rel="rdfs-seeAlso">pg_escape_bytea()</a> - Escape a string for insertion into a bytea field</span></li> <li class="member"> <span class="function"><a href="function.pg-escape-string.html" class="function" rel="rdfs-seeAlso">pg_escape_string()</a> - Escape a string for query</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-tty.html">pg_tty</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-untrace.html">pg_untrace</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>