xref: /PHP-8.2/ext/pgsql/tests/pg_select_001.phpt (revision 1f427779)
1--TEST--
2PostgreSQL pg_select() - basic test using schema
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php include("skipif.inc"); ?>
7--FILE--
8<?php
9
10include('config.inc');
11
12$conn = pg_connect($conn_str);
13
14pg_query($conn, 'CREATE SCHEMA phptests');
15
16pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
17pg_query($conn, 'INSERT INTO phptests.foo VALUES (1,2)');
18pg_query($conn, 'INSERT INTO phptests.foo VALUES (2,3)');
19
20pg_query($conn, 'CREATE TABLE phptests.bar (id4 INT, id3 INT)');
21pg_query($conn, 'INSERT INTO phptests.bar VALUES (4,5)');
22pg_query($conn, 'INSERT INTO phptests.bar VALUES (6,7)');
23
24/* Nonexistent table */
25var_dump(pg_select($conn, 'foo', array('id' => 1)));
26
27/* Existent column */
28var_dump(pg_select($conn, 'phptests.foo', array('id' => 1)));
29
30/* Testing with inexistent column */
31var_dump(pg_select($conn, 'phptests.bar', array('id' => 1)));
32
33/* Existent column */
34var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4)));
35
36/* Use a different result type */
37var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4), 0, PGSQL_NUM));
38
39pg_query($conn, 'DROP TABLE phptests.foo');
40pg_query($conn, 'DROP TABLE phptests.bar');
41pg_query($conn, 'DROP SCHEMA phptests');
42
43?>
44--EXPECTF--
45Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d
46bool(false)
47array(1) {
48  [0]=>
49  array(2) {
50    ["id"]=>
51    string(1) "1"
52    ["id2"]=>
53    string(1) "2"
54  }
55}
56
57Notice: pg_select(): Invalid field name (id) in values in %s on line %d
58bool(false)
59array(1) {
60  [0]=>
61  array(2) {
62    ["id4"]=>
63    string(1) "4"
64    ["id3"]=>
65    string(1) "5"
66  }
67}
68array(1) {
69  [0]=>
70  array(2) {
71    [0]=>
72    string(1) "4"
73    [1]=>
74    string(1) "5"
75  }
76}
77