<?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-select.php',
    1 => 'pg_select',
    2 => 'Select records',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Функції',
  ),
  'prev' => 
  array (
    0 => 'function.pg-result-status.php',
    1 => 'pg_result_status',
  ),
  'next' => 
  array (
    0 => 'function.pg-send-execute.php',
    1 => 'pg_send_execute',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-select.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-select" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_select</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_select</span> &mdash; <span class="dc-title">
   Select records
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-select-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_select</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.pgsql-connection.php" class="type PgSql\Connection">PgSql\Connection</a></span> <code class="parameter">$connection</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">$table_name</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$conditions</code><span class="initializer"> = []</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">$flags</code><span class="initializer"> = <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-exec">PGSQL_DML_EXEC</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">$mode</code><span class="initializer"> = <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_select()</strong></span> selects records specified by
   <code class="parameter">conditions</code> which has
   <code class="literal">field=&gt;value</code>. For a successful query, it returns an
   array containing all records and fields that match the condition
   specified by <code class="parameter">conditions</code>.
  </p>
  <p class="para">
   If <code class="parameter">flags</code> is set,
   <span class="function"><a href="function.pg-convert.php" class="function">pg_convert()</a></span> is applied to
   <code class="parameter">conditions</code> with the specified flags.
  </p>
  <p class="para">
   If <code class="parameter">mode</code> is set,
   the return value will be in the form of an array
   with <strong><code><a href="pgsql.constants.php#constant.pgsql-num">PGSQL_NUM</a></code></strong>, an associative array
   with <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong> (default) or both
   with <strong><code><a href="pgsql.constants.php#constant.pgsql-both">PGSQL_BOTH</a></code></strong>.
  </p>
  <p class="para">
   By default <span class="function"><strong>pg_select()</strong></span> passes raw values. Values
   must be escaped or PGSQL_DML_ESCAPE option must be
   specified. PGSQL_DML_ESCAPE quotes and escapes
   parameters/identifiers. Therefore, table/column names became case
   sensitive.
  </p>
  <p class="para">
   Note that neither escape nor prepared query can protect LIKE query,
   JSON, Array, Regex, etc. These parameters should be handled
   according to their contexts. i.e. Escape/validate values.
  </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.pg-select-parameters">
   <h3 class="title">Параметри</h3>
   <p class="para">
    <dl>
     
      <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>.</p>
      </dd>
     
     
      <dt><code class="parameter">table_name</code></dt>
      <dd>
       <p class="para">
        Name of the table from which to select rows.
       </p>
      </dd>
     
     
      <dt><code class="parameter">conditions</code></dt>
      <dd>
       <p class="para">
        An <span class="type"><a href="language.types.array.php" class="type array">array</a></span> whose keys are field names in the table <code class="parameter">table_name</code>,
        and whose values are the conditions that a row must meet to be retrieved.
        As of PHP 8.4.0, when an empty array is provided, no conditions will apply.
        Previously, the function failed with an empty <code class="parameter">conditions</code> argument.
       </p>
      </dd>
     
     
      <dt><code class="parameter">flags</code></dt>
      <dd>
       <p class="para">
        Any number of <strong><code><a href="pgsql.constants.php#constant.pgsql-conv-force-null">PGSQL_CONV_FORCE_NULL</a></code></strong>,
        <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-no-conv">PGSQL_DML_NO_CONV</a></code></strong>,
        <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-escape">PGSQL_DML_ESCAPE</a></code></strong>,
        <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-exec">PGSQL_DML_EXEC</a></code></strong>,
        <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-async">PGSQL_DML_ASYNC</a></code></strong> or
        <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-string">PGSQL_DML_STRING</a></code></strong> combined. If <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-string">PGSQL_DML_STRING</a></code></strong> is part of the
        <code class="parameter">flags</code> then the query string is returned. When <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-no-conv">PGSQL_DML_NO_CONV</a></code></strong>
        or <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-escape">PGSQL_DML_ESCAPE</a></code></strong> is set, it does not call <span class="function"><a href="function.pg-convert.php" class="function">pg_convert()</a></span> internally.
       </p>
      </dd>
     
     
      <dt><code class="parameter">mode</code></dt>
      <dd>
       <p class="para">
        Any number of <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong>,
        <strong><code><a href="pgsql.constants.php#constant.pgsql-num">PGSQL_NUM</a></code></strong> or
        <strong><code><a href="pgsql.constants.php#constant.pgsql-both">PGSQL_BOTH</a></code></strong>
        If <strong><code><a href="pgsql.constants.php#constant.pgsql-assoc">PGSQL_ASSOC</a></code></strong> is set the return value will be an associative <span class="type"><a href="language.types.array.php" class="type array">array</a></span>,
        with <strong><code><a href="pgsql.constants.php#constant.pgsql-num">PGSQL_NUM</a></code></strong> the return value will be an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>, and
        with <strong><code><a href="pgsql.constants.php#constant.pgsql-both">PGSQL_BOTH</a></code></strong> the return value will be both an associative and
        numerically indexed <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-select-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns <span class="type"><a href="language.types.string.php" class="type string">string</a></span> if <strong><code><a href="pgsql.constants.php#constant.pgsql-dml-string">PGSQL_DML_STRING</a></code></strong> is passed
   via <code class="parameter">flags</code>, otherwise it returns an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> on success,  або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>
        <code class="parameter">conditions</code> is now optional.
       </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>7.1.0</td>
       <td>
        The <code class="parameter">mode</code> parameter was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-select-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>pg_select()</strong></span> example</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php <br />  $db </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 />  </span><span style="color: #FF8000">// This is safe somewhat, since all values are escaped.<br />  // However PostgreSQL supports JSON/Array. These are not<br />  // safe by neither escape nor prepared query.<br />  </span><span style="color: #0000BB">$rec </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">'post_log'</span><span style="color: #007700">, </span><span style="color: #0000BB">$_POST</span><span style="color: #007700">, </span><span style="color: #0000BB">PG_DML_ESCAPE</span><span style="color: #007700">);<br />  if (</span><span style="color: #0000BB">$rec</span><span style="color: #007700">) {<br />      echo </span><span style="color: #DD0000">"Records selected\n"</span><span style="color: #007700">;<br />      </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$rec</span><span style="color: #007700">);<br />  } else {<br />      echo </span><span style="color: #DD0000">"User must have sent wrong inputs\n"</span><span style="color: #007700">;<br />  }<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.pg-select-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-convert.php" class="function" rel="rdfs-seeAlso">pg_convert()</a> - Convert associative array values into forms suitable for SQL statements</span></li>
   </ul>
  </p>
 </div>

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