13pg_select_9.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. --TEST--
  2. PostgreSQL pg_select() (9.0+)
  3. --EXTENSIONS--
  4. pgsql
  5. --SKIPIF--
  6. <?php
  7. include("skipif.inc");
  8. skip_server_version('9.0', '<');
  9. ?>
  10. --FILE--
  11. <?php
  12. error_reporting(E_ALL);
  13. include 'config.inc';
  14. $db = pg_connect($conn_str);
  15. pg_query($db, "SET bytea_output = 'hex'");
  16. $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
  17. $ids = array('num'=>'1234');
  18. $res = pg_select($db, $table_name, $ids) or print "Error\n";
  19. var_dump($res);
  20. echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
  21. echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
  22. /* Invalid values */
  23. try {
  24. $converted = pg_select($db, $table_name, [5 => 'AAA']);
  25. } catch (\ValueError $e) {
  26. echo $e->getMessage(), \PHP_EOL;
  27. }
  28. try {
  29. $converted = pg_select($db, $table_name, ['AAA']);
  30. } catch (\ValueError $e) {
  31. echo $e->getMessage(), \PHP_EOL;
  32. }
  33. try {
  34. $converted = pg_select($db, $table_name, ['num' => []]);
  35. } catch (\TypeError $e) {
  36. echo $e->getMessage(), \PHP_EOL;
  37. }
  38. try {
  39. $converted = pg_select($db, $table_name, ['num' => new stdClass()]);
  40. } catch (\TypeError $e) {
  41. echo $e->getMessage(), \PHP_EOL;
  42. }
  43. try {
  44. $converted = pg_select($db, $table_name, ['num' => $db]);
  45. var_dump($converted);
  46. } catch (\TypeError $e) {
  47. echo $e->getMessage(), \PHP_EOL;
  48. }
  49. echo "Ok\n";
  50. ?>
  51. --EXPECT--
  52. array(2) {
  53. [0]=>
  54. array(3) {
  55. ["num"]=>
  56. string(4) "1234"
  57. ["str"]=>
  58. string(3) "AAA"
  59. ["bin"]=>
  60. string(8) "\x424242"
  61. }
  62. [1]=>
  63. array(3) {
  64. ["num"]=>
  65. string(4) "1234"
  66. ["str"]=>
  67. string(3) "AAA"
  68. ["bin"]=>
  69. string(8) "\x424242"
  70. }
  71. }
  72. SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
  73. SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
  74. Array of values must be an associative array with string keys
  75. Array of values must be an associative array with string keys
  76. Values must be of type string|int|float|bool|null, array given
  77. Values must be of type string|int|float|bool|null, stdClass given
  78. Values must be of type string|int|float|bool|null, PgSql\Connection given
  79. Ok