<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.pg-convert.php',
    1 => 'pg_convert',
    2 => 'Convert associative array values into forms suitable for SQL statements',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Functions',
  ),
  'prev' => 
  array (
    0 => 'function.pg-consume-input.php',
    1 => 'pg_consume_input',
  ),
  'next' => 
  array (
    0 => 'function.pg-copy-from.php',
    1 => 'pg_copy_from',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-convert.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-convert" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_convert</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_convert</span> &mdash; <span class="dc-title">
   Convert associative array values into forms suitable for SQL statements
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-convert-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_convert</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">$values</code></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"> = 0</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.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_convert()</strong></span> checks and converts the values in
   <code class="parameter">values</code> into suitable values for use in an SQL
   statement. Precondition for <span class="function"><strong>pg_convert()</strong></span> is the 
   existence of a table <code class="parameter">table_name</code> which has at least
   as many columns as <code class="parameter">values</code> has elements. The
   fieldnames in <code class="parameter">table_name</code> must match the indices in
   <code class="parameter">values</code> and the corresponding datatypes must be
   compatible. Returns an array with the converted values on success, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
   otherwise.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Boolean values are accepted and converted to PostgreSQL booleans.
    String representations of boolean values are also supported. <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> is
    converted to PostgreSQL NULL.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-convert-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">connection</code></dt>
     <dd>
      <p class="para">An <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span> instance.</p>
     </dd>
    
    
     <dt><code class="parameter">table_name</code></dt>
     <dd>
      <p class="para">
       Name of the table against which to convert types.
      </p>
     </dd>
    
    
     <dt><code class="parameter">values</code></dt>
     <dd>
      <p class="para">
       Data to be converted.
      </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-ignore-default">PGSQL_CONV_IGNORE_DEFAULT</a></code></strong>,
       <strong><code><a href="pgsql.constants.php#constant.pgsql-conv-force-null">PGSQL_CONV_FORCE_NULL</a></code></strong> or
       <strong><code><a href="pgsql.constants.php#constant.pgsql-conv-ignore-not-null">PGSQL_CONV_IGNORE_NOT_NULL</a></code></strong>, combined.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-convert-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   An <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of converted values,  or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.pg-convert-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   A <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> or <span class="classname"><a href="class.typeerror.php" class="classname">TypeError</a></span> is thrown
   when the value or type of field does not match properly with a PostgreSQL&#039;s type.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-convert-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Now throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> or <span class="classname"><a href="class.typeerror.php" class="classname">TypeError</a></span> error
       when the value or type of field does not match properly with a PostgreSQL&#039;s type;
       previously an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> was emitted.
      </td>
     </tr>

     <tr>
 <td>8.1.0</td>
 <td>
  The <code class="parameter">connection</code> parameter expects an <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span>
  instance now; previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was expected.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-convert-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>pg_convert()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php <br />  $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: #0000BB">$tmp </span><span style="color: #007700">= array(<br />      </span><span style="color: #DD0000">'author' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'Joe Thackery'</span><span style="color: #007700">,<br />      </span><span style="color: #DD0000">'year' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">2005</span><span style="color: #007700">,<br />      </span><span style="color: #DD0000">'title' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'My Life, by Joe Thackery'<br />  </span><span style="color: #007700">);<br />  <br />  </span><span style="color: #0000BB">$vals </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_convert</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">, </span><span style="color: #DD0000">'authors'</span><span style="color: #007700">, </span><span style="color: #0000BB">$tmp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.pg-convert-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-meta-data.php" class="function" rel="rdfs-seeAlso">pg_meta_data()</a> - Get meta data for table</span></li>
    <li><span class="function"><a href="function.pg-insert.php" class="function" rel="rdfs-seeAlso">pg_insert()</a> - Insert array into table</span></li>
    <li><span class="function"><a href="function.pg-select.php" class="function" rel="rdfs-seeAlso">pg_select()</a> - Select records</span></li>
    <li><span class="function"><a href="function.pg-update.php" class="function" rel="rdfs-seeAlso">pg_update()</a> - Update table</span></li>
    <li><span class="function"><a href="function.pg-delete.php" class="function" rel="rdfs-seeAlso">pg_delete()</a> - Deletes records</span></li>
   </ul>
  </p>
 </div>

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