<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pgsql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.pg-trace.php',
    1 => 'pg_trace',
    2 => 'Enable tracing a PostgreSQL connection',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Функції',
  ),
  'prev' => 
  array (
    0 => 'function.pg-socket.php',
    1 => 'pg_socket',
  ),
  'next' => 
  array (
    0 => 'function.pg-transaction-status.php',
    1 => 'pg_transaction_status',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-trace.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-trace" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_trace</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_trace</span> &mdash; <span class="dc-title">Enable tracing a PostgreSQL connection</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-trace-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_trace</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code><span class="initializer"> = &quot;w&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.pgsql-connection.php" class="type PgSql\Connection">PgSql\Connection</a></span></span> <code class="parameter">$connection</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$trace_mode</code><span class="initializer"> = 0</span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_trace()</strong></span> enables tracing of the PostgreSQL
   frontend/backend communication to a file. To fully understand the results,
   one needs to be familiar with the internals of PostgreSQL
   communication protocol.
  </p>
  <p class="para">For those who are not, it can still be
   useful for tracing errors in queries sent to the server, you
   could do for example <strong class="command">grep &#039;^To backend&#039;
   trace.log</strong> and see what queries actually were sent to the
   PostgreSQL server. For more information, refer to the
   <a href="http://www.postgresql.org/docs/current/interactive/" class="link external">&raquo;&nbsp;PostgreSQL Documentation</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-trace-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       The full path and file name of the file in which to write the
       trace log.  Same as in <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
       An optional file access mode, same as for <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">connection</code></dt>
     <dd>
      <p class="para">Примірник
<span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span>. Якщо параметр
<code class="parameter">connection</code> — <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, то виконується стандартне
з&#039;єднання, тобто останнє, виконане функцією <span class="function"><a href="function.pg-connect.php" class="function">pg_connect()</a></span>
або <span class="function"><a href="function.pg-pconnect.php" class="function">pg_pconnect()</a></span>. <div class="warning"><strong class="warning">Увага</strong><p class="simpara">Починаючи з PHP 8.1.0,
використання стандартного з&#039;єднання є
застарілим.</p></div></p>
     </dd>
    
    
     <dt><code class="parameter">trace_mode</code></dt>
     <dd>
      <p class="para">
       An optional trace mode with the following constants
       <strong><code><a href="pgsql.constants.php#constant.pgsql-trace-suppress-timestamps">PGSQL_TRACE_SUPPRESS_TIMESTAMPS</a></code></strong> and
       <strong><code><a href="pgsql.constants.php#constant.pgsql-trace-regress-mode">PGSQL_TRACE_REGRESS_MODE</a></code></strong>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-trace-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Повертає <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> у разі успіху або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-trace-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       <code class="parameter">trace_mode</code> has been added.
      </td>
     </tr>

     <tr>
 <td>8.1.0</td>
 <td>
  Тепер параметр <code class="parameter">connection</code> має бути примірником
  <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span>. Раніше очікувався <a href="language.types.resource.php" class="link">resource</a>.
 </td>
</tr>

     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">connection</code> is now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-trace-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>pg_trace()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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 />if (</span><span style="color: #0000BB">$pgsql_conn</span><span style="color: #007700">) {<br />   </span><span style="color: #0000BB">pg_trace</span><span style="color: #007700">(</span><span style="color: #DD0000">'/tmp/trace.log'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">, </span><span style="color: #0000BB">$pgsql_conn</span><span style="color: #007700">);<br />   </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT 1"</span><span style="color: #007700">);<br />   </span><span style="color: #0000BB">pg_untrace</span><span style="color: #007700">(</span><span style="color: #0000BB">$pgsql_conn</span><span style="color: #007700">);<br />   </span><span style="color: #FF8000">// Now /tmp/trace.log will contain backend communication<br /></span><span style="color: #007700">} else {<br />   print </span><span style="color: #0000BB">pg_last_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$pgsql_conn</span><span style="color: #007700">);<br />   exit;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.pg-trace-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Opens file or URL</span></li>
    <li><span class="function"><a href="function.pg-untrace.php" class="function" rel="rdfs-seeAlso">pg_untrace()</a> - Disable tracing of a PostgreSQL connection</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>