pg_convert
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_convert — 將關聯的陣列值轉換為適合 SQL 語句的格式。
說明
resource
$connection,string
$table_name,array
$assoc_array,int
$options = 0): array
pg_convert() 檢查 assoc_array
中的值並將其轉換為為適用於 SQL 語句的值。pg_convert()
的前提條件是現有的表 table_name
中具有的列至少有 assoc_array
中的單元那麼多。table_name
中的欄位名以及欄位值必須和 assoc_array
中的鍵名及值匹配。如果成功則返回一個包括轉換后的值的陣列,否則返回 false。
注意:
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.
此函式是實驗性的。此函式的表象,包括名稱及其相關文件都可能在未來的 PHP 發佈版本中未通知就被修改。使用本函式風險自擔。
參數
-
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.
返回值
An array of converted values, or false on error.
範例
示例 #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);
?>