pg_select_001.phpt 1.6 KB

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