Php/docs/function.pg-insert
pg_insert
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
pg_insert — 将数组插入到表中
说明
pg_insert
( resource $connection
, string $table_name
, array $assoc_array
[, int $options = PGSQL_DML_EXEC
] ) : mixed
pg_insert() 将 assoc_array 数组中的值插入到由
table_name 指定的表中。
如果给出了参数
options ,则函数 pg_convert()
会按照给定选项被作用到 assoc_array 上
Warning 此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担。
参数
connection- PostgreSQL database connection resource.
table_name- Name of the table into which to insert rows.
table_name中的列必须至少要有assoc_array中的单元那么多。 assoc_arraytable_name中的字段名以及字段值必须和 array 参数 中的键名及值匹配。options- Any number of
PGSQL_CONV_OPTS,PGSQL_DML_NO_CONV,PGSQL_DML_EXEC,PGSQL_DML_ASYNCorPGSQL_DML_STRINGcombined. IfPGSQL_DML_STRINGis part of theoptionsthen query string is returned.
返回值
成功时返回 true, 或者在失败时返回 false。 Returns string if PGSQL_DML_STRING is passed
via options.
范例
Example #1 pg_insert() example
<?php $dbconn = pg_connect('dbname=foo'); // This is safe, since $_POST is converted automatically $res = pg_insert($dbconn, 'post_log', $_POST); if ($res) { echo "POST data is successfully logged\n"; } else { echo "User must have sent wrong inputs\n"; }?>