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