pg_convert

(PHP 4 >= 4.3.0, PHP 5)

pg_convert --  将关联的数组值转换为适合 SQL 语句的格式。

说明

array pg_convert ( resource connection, string table_name, array assoc_array [, int options] )

pg_convert() 检查 assoc_array 中的值并将其转换为为适用于 SQL 语句的值。pg_convert() 的前提条件是现有的表 table_name 中具有的列至少有 assoc_array 中的单元那么多。table_name 中的字段名以及字段值必须和 assoc_array 中的键名及值匹配。如果成功则返回一个包括转换后的值的数组,否则返回 FALSE

警告

本函数是实验性的。本函数的行为,包括函数名称以及其它任何关于本函数的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本函数风险自担。

参见 pg_meta_data()


add a note add a note User Contributed Notes
Andrew Falanga
25-Feb-2005 04:03
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.
01-Apr-2004 12:02
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.
dharana at dharana dot net
12-May-2003 09:28
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.