Rechercher une fonction PHP

pg_convert

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

pg_convert Convert associative array values into forms suitable for SQL statements

Description

pg_convert ( resource $connection , string $table_name , array $assoc_array [, int $options = 0 ] ) : array

pg_convert() checks and converts the values in assoc_array into suitable values for use in an SQL statement. Precondition for pg_convert() is the existence of a table table_name which has at least as many columns as assoc_array has elements. The fieldnames in table_name must match the indices in assoc_array and the corresponding datatypes must be compatible. Returns an array with the converted values on success, FALSE otherwise.

Note:

Since PHP 5.6.0, it accepts boolean values, converting them to PostgreSQL booleans. String representations of boolean values are also supported. NULL is converted to PostgreSQL NULL.

Prior to PHP 5.6.0, if there are boolean fields in table_name don't use the constant TRUE in assoc_array. It will be converted to the string 'TRUE' which is not a valid entry for boolean fields in PostgreSQL. Use one of "t", "true", 1, "y", "yes" instead.

PHP: pg_convert - Manual Home of Manuel PHP  Contents Haut

Parameters

connection

PostgreSQL database connection resource.

table_name

Name of the table against which to convert types.

assoc_array

Data to be converted.

options

Any number of PGSQL_CONV_IGNORE_DEFAULT, PGSQL_CONV_FORCE_NULL or PGSQL_CONV_IGNORE_NOT_NULL, combined.

PHP: pg_convert - Manual Home of Manuel PHP  Contents Haut

Return Values

An array of converted values, or FALSE on error.

PHP: pg_convert - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 pg_convert() example

<?php 
  $dbconn 
pg_connect('dbname=foo');
  
  
$tmp = array(
      
'author' => 'Joe Thackery',
      
'year' => 2005,
      
'title' => 'My Life, by Joe Thackery'
  
);
  
  
$vals pg_convert($dbconn'authors'$tmp);
?>

PHP: pg_convert - Manual Home of Manuel PHP  Contents Haut

Changelog

Version Description
5.6.0 No longer experimental. Boolean/NULL data types are supported. Unknown/unsupported data types are escaped without validation. pg_convert() can be used with any data types.

PHP: pg_convert - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-pg-convert.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut