pg_convert

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

pg_convert 將關(guān)聯(lián)的數(shù)組值轉(zhuǎn)換為適合 SQL 語句的格式。

說明

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

pg_convert() 檢查 assoc_array 中的值并將其轉(zhuǎn)換為為適用于 SQL 語句的值。pg_convert() 的前提條件是現(xiàn)有的表 table_name 中具有的列至少有 assoc_array 中的單元那么多。table_name 中的字段名以及字段值必須和 assoc_array 中的鍵名及值匹配。如果成功則返回一個包括轉(zhuǎn)換后的值的數(shù)組,否則返回 false。

注意:

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 no valid entry for boolean fields in PostgreSQL. Use one of t, true, 1, y, yes instead.

警告

此函數(shù)是實驗性的。此函數(shù)的表象,包括名稱及其相關(guān)文檔都可能在未來的 PHP 發(fā)布版本中未通知就被修改。使用本函數(shù)風(fēng)險自擔(dān)。

參數(shù)

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.

返回值

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);
?>

參見