注意:
Not all functions are supported by all builds. It depends on your libpq (The PostgreSQL C client library) version and how libpq is compiled. If PHP PostgreSQL extensions are missing, then it is because your libpq version does not support them.
注意:
Most PostgreSQL functions accept
connectionas the optional first parameter. If it is not provided, the last opened connection is used. If it doesn't exist, functions returnfalse.
注意:
PostgreSQL automatically folds all identifiers (e.g. table/column names) to lower-case values at object creation time and at query time. To force the use of mixed or upper case identifiers, you must escape the identifier using double quotes ("").
注意:
PostgreSQL does not have special commands for fetching database schema information (eg. all the tables in the current database). Instead, there is a standard schema named
information_schemacontaining system views with all the necessary information, in an easily queryable form. See the » PostgreSQL Documentation for full details.
A simple conversion for 1D PostgreSQL array data:
// =====
//Example #1 (An array of IP addresses):
<?php
$pgsqlArr = '{192.168.1.1,10.1.1.1}';
preg_match('/^{(.*)}$/', $pgsqlArr, $matches);
$phpArr = str_getcsv($matches[1]);
print_r($phpArr);
}
// Output:
// Array
// (
// [0] => 192.168.1.1
// [1] => 10.1.1.1
// )
// =====
// =====
// Example #2 (An array of strings including spaces and commas):
<?php
$pgsqlArr = '{string1,string2,"string,3","string 4"}';
preg_match('/^{(.*)}$/', $pgsqlArr, $matches);
$phpArr = str_getcsv($matches[1]);
print_r($phpArr);
}
// Output:
// Array
// (
// [0] => string1
// [1] => string2
// [2] => string,3
// [3] => string 4
// )
// =====I've found another function to mimic the following mysql list tables function (http://www.php.net/manual/en/function.mysql-list-tables.php) that's more useful for my target:
function pg_list_tables() {
$sql = "SELECT a.relname AS Name
FROM pg_class a, pg_user b
WHERE ( relkind = 'r') and relname !~ '^pg_' AND relname !~ '^sql_'
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
return(pg_query($conn, $sql));
}Running RedHat Linux and Apache with suexec enabled you must include pgsql.so on each .php file using dl("pgsql.so") and remove "extension=pgsql.so" from php.ini, otherwise Apache (httpd) will not start.