xref: /php-src/ext/pgsql/tests/pg_select_001.phpt (revision c15988aa)
1--TEST--
2PostgreSQL pg_select() - basic test using schema
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("inc/skipif.inc"); ?>
7--FILE--
8<?php
9
10include('inc/config.inc');
11$schema_name = 'schema_pg_select_001';
12
13$conn = pg_connect($conn_str);
14
15pg_query($conn, "CREATE SCHEMA {$schema_name}");
16
17pg_query($conn, "CREATE TABLE {$schema_name}.foo (id INT, id2 INT)");
18pg_query($conn, "INSERT INTO {$schema_name}.foo VALUES (1,2)");
19pg_query($conn, "INSERT INTO {$schema_name}.foo VALUES (2,3)");
20
21pg_query($conn, "CREATE TABLE {$schema_name}.bar (id4 INT, id3 INT)");
22pg_query($conn, "INSERT INTO {$schema_name}.bar VALUES (4,5)");
23pg_query($conn, "INSERT INTO {$schema_name}.bar VALUES (6,7)");
24
25/* Nonexistent table */
26var_dump(pg_select($conn, 'foo', array('id' => 1)));
27
28/* Existent column */
29var_dump(pg_select($conn, "{$schema_name}.foo", array('id' => 1)));
30
31/* Testing with inexistent column */
32var_dump(pg_select($conn, "{$schema_name}.bar", array('id' => 1)));
33
34/* Existent column */
35var_dump(pg_select($conn, "{$schema_name}.bar", array('id4' => 4)));
36
37/* Use a different result type */
38var_dump(pg_select($conn, "{$schema_name}.bar", array('id4' => 4), 0, PGSQL_NUM));
39
40/* Empty array */
41var_dump(pg_select($conn, "{$schema_name}.bar", array()));
42
43/* No array */
44var_dump(pg_select($conn, "{$schema_name}.bar"));
45
46?>
47--CLEAN--
48<?php
49require_once('inc/config.inc');
50$schema_name = 'schema_pg_select_001';
51
52$conn = pg_connect($conn_str);
53
54pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.foo");
55pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.bar");
56pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
57?>
58--EXPECTF--
59Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d
60bool(false)
61array(1) {
62  [0]=>
63  array(2) {
64    ["id"]=>
65    string(1) "1"
66    ["id2"]=>
67    string(1) "2"
68  }
69}
70
71Notice: pg_select(): Invalid field name (id) in values in %s on line %d
72bool(false)
73array(1) {
74  [0]=>
75  array(2) {
76    ["id4"]=>
77    string(1) "4"
78    ["id3"]=>
79    string(1) "5"
80  }
81}
82array(1) {
83  [0]=>
84  array(2) {
85    [0]=>
86    string(1) "4"
87    [1]=>
88    string(1) "5"
89  }
90}
91array(2) {
92  [0]=>
93  array(2) {
94    ["id4"]=>
95    string(1) "4"
96    ["id3"]=>
97    string(1) "5"
98  }
99  [1]=>
100  array(2) {
101    ["id4"]=>
102    string(1) "6"
103    ["id3"]=>
104    string(1) "7"
105  }
106}
107array(2) {
108  [0]=>
109  array(2) {
110    ["id4"]=>
111    string(1) "4"
112    ["id3"]=>
113    string(1) "5"
114  }
115  [1]=>
116  array(2) {
117    ["id4"]=>
118    string(1) "6"
119    ["id3"]=>
120    string(1) "7"
121  }
122}
123