<!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>Returns the last notice message from PostgreSQL server</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-last-error.html">pg_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-last-oid.html">pg_last_oid</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-last-notice" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_last_notice</h1> <p class="verinfo">(PHP 4 >= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pg_last_notice</span> — <span class="dc-title"> Returns the last notice message from PostgreSQL server </span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-last-notice-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>pg_last_notice</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code><span class="initializer"> = PGSQL_NOTICE_LAST</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_last_notice()</strong></span> returns the last notice message from the PostgreSQL server on the specified <code class="parameter">connection</code>. The PostgreSQL server sends notice messages in several cases, for instance when creating a <em>SERIAL</em> column in a table. </p> <p class="para"> With <span class="function"><strong>pg_last_notice()</strong></span>, you can avoid issuing useless queries by checking whether or not the notice is related to your transaction. </p> <p class="para"> Notice message tracking can be set to optional by setting 1 for <em>pgsql.ignore_notice</em> in <var class="filename">php.ini</var>. </p> <p class="para"> Notice message logging can be set to optional by setting 0 for <em>pgsql.log_notice</em> in <var class="filename">php.ini</var>. Unless <em>pgsql.ignore_notice</em> is set to 0, notice message cannot be logged. </p> </div> <div class="refsect1 parameters" id="refsect1-function.pg-last-notice-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">connection</code></dt> <dd> <p class="para"> PostgreSQL database connection resource. </p> </dd> <dt> <code class="parameter">option</code></dt> <dd> <p class="para"> One of <strong><code>PGSQL_NOTICE_LAST</code></strong> (to return last notice), <strong><code>PGSQL_NOTICE_ALL</code></strong> (to return all notices), or <strong><code>PGSQL_NOTICE_CLEAR</code></strong> (to clear notices). </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-last-notice-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 last notice on the given <code class="parameter">connection</code> with <strong><code>PGSQL_NOTICE_LAST</code></strong>, an <span class="type"><a href="language.types.array.html" class="type array">array</a></span> with <strong><code>PGSQL_NOTICE_ALL</code></strong>, a <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span> with <strong><code>PGSQL_NOTICE_CLEAR</code></strong>, or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-last-notice-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2565"> <p><strong>Example #1 <span class="function"><strong>pg_last_notice()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $pgsql_conn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=mark host=localhost"</span><span style="color: #007700">);<br /> <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">"CREATE TABLE test (id SERIAL)"</span><span style="color: #007700">);<br /> <br /> </span><span style="color: #0000BB">$notice </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_last_notice</span><span style="color: #007700">(</span><span style="color: #0000BB">$pgsql_conn</span><span style="color: #007700">);<br /> <br /> echo </span><span style="color: #0000BB">$notice</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> CREATE TABLE will create implicit sequence "test_id_seq" for "serial" column "test.id" </pre></div> </div> </div> </p> </div> <div class="refsect1 changelog" id="refsect1-function.pg-last-notice-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>7.1.0</td> <td> The <code class="parameter">option</code> parameter was added. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-last-notice-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.pg-query.html" class="function" rel="rdfs-seeAlso">pg_query()</a> - Execute a query</span></li> <li class="member"><span class="function"><a href="function.pg-last-error.html" class="function" rel="rdfs-seeAlso">pg_last_error()</a> - Get the last error message string of a connection</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-last-error.html">pg_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-last-oid.html">pg_last_oid</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>