David mentioned that you can't do a Select all.
However, when executing this script:
<?php
$conn_string = "dbname=mydb";
$db = pg_connect($conn_string);
$selectfields = array("imgid" => "");
$records = pg_select($db,"mmsfiles",$selectfields);
print_r($records);
?>
...I get this result:
Array
(
[0] => Array
(
[imgid] => 1
[file] => /home/wietse/public_html/mms/images/1.gif
[thumb] =>
)
[1] => Array
(
[imgid] => 2
[file] => /home/wietse/public_html/mms/images/2.gif
[thumb] =>
)
[2] => Array
(
[imgid] => 3
[file] => /home/wietse/public_html/mms/images/3.gif
[thumb] =>
)
[3] => Array
(
[imgid] => 4
[file] => /home/wietse/public_html/mms/images/4.gif
[thumb] =>
)
)
pg_select
説明
mixed pg_select ( resource connection, string table_name, array assoc_array [, int options] )pg_select() は、field=>value 形式の assoc_array で指定したレコードを選択します。 クエリに成功した場合、assoc_array で指定した条件に マッチする全てのレコードとフィールドを含む配列が返されます。
options が指定された場合、 指定したフラグとともに pg_convert() が assoc_array に適用されます。
| 警告 |
この関数は、 実験的 なものです。この関数の動作・ 名前・その他ドキュメントに書かれている事項は、予告なく、将来的な PHP のリリースにおいて変更される可能性があります。 この関数は自己責任で使用してください。 |
パラメータ
- connection
PostgreSQL データベースの接続リソース。
- table_name
行を選択するテーブルの名前。
- assoc_array
テーブル table_name のフィールド名をキーに、 そして取得対象となる行にマッチするデータを値にもつ配列。
- options
PGSQL_CONV_FORCE_NULL、 PGSQL_DML_NO_CONV、 PGSQL_DML_EXEC、 PGSQL_DML_ASYNC あるいは PGSQL_DML_STRING の組み合わせ。 options の一部に PGSQL_DML_STRING が含まれていた場合、 クエリ文字列が返されます。
pg_select
wietse at cj2 dot nl
28-Feb-2006 01:20
28-Feb-2006 01:20
david dot tulloh at infaze dot com dot au
17-May-2005 01:46
17-May-2005 01:46
Valid options are PGSQL_DML_NO_CONV, PGSQL_DML_EXEC, PGSQL_DMP_ASYNC, PGSQL_DML_STRING (pulled out of source code).
This function does not support selecting from multiple tables. You can get around this by setting the PGSQL_DML_NO_CONV option. This prevents the error which occurs when the function tries to convert the condition array.
I think it is also important to point out that the table_name field is not safe, particularily with the PGSQL_DML_NO_CONV option.
The arguements array field is compulsory, as documented. What isn't so clear is that the array has to actually have some values in it, you can't do a select all.
In summary, this function is good for a very small subset of basic queries. If you are after anything more complex you are better off with pg_query.