Why does this function, pg_convert(), reject the string 'TRUE' as a valid value for the boolean types? I'm using PHP 4.3.9 and my web page originally set the value for submission to update, to 'TRUE'. pg_convert() threw it back to me saying that it's not a valid value for boolean types. However, the postgresql website says otherwise. See http://www.postgresql.org/docs/7.4/static/datatype-boolean.html for the context of my question/comment.
pg_convert
(PHP 4 >= 4.3.0, PHP 5)
pg_convert — Convert associative array values into suitable for SQL statement
Description
$connection
, string $table_name
, array $assoc_array
[, int $options = 0
] )
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:
If there are boolean fields in
table_namedon't use the constantTRUEinassoc_array. It will be converted to the string 'TRUE' which is no valid entry for boolean fields in PostgreSQL. Use one of t, true, 1, y, yes instead.
This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk.
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_NULLorPGSQL_CONV_IGNORE_NOT_NULL, combined.
Return Values
An array of converted values, or FALSE on error.
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);
?>
The only options that I see are:
PGSQL_CONV_IGNORE_DEFAULT - Do not use DEAFULT value by removing field from returned array
PGSQL_CONV_FORCE_NULL - Convert to NULL if string is null string
PGSQL_CONV_IGNORE_NOT_NULL - Ignore NOT NULL constraints
These are constants, so don't quote them or anything.
I've found "options" possible values:
PG_CONV_CHECK - check only
PG_CONV_STRICT - raise warning for non fatal error
PG_CONV_QUOTE - add quote around values for vchar, text datetime.
PG_CONV_SLASH - add slashes if it needed.
PG_CONV_NULLCHK - check values are defined for NOT NULL fields.
PG_CONV_NO_DEFAULT - ignore default value even if value is empty string.
