12pg_insert_9.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. PostgreSQL pg_insert() (9.0+)
  3. --EXTENSIONS--
  4. pgsql
  5. --SKIPIF--
  6. <?php
  7. include("skipif.inc");
  8. skip_bytea_not_hex();
  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 standard_conforming_strings = 0");
  16. $fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
  17. pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
  18. echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
  19. echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
  20. var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) );
  21. /* Invalid values */
  22. try {
  23. $converted = pg_insert($db, $table_name, [5 => 'AAA']);
  24. } catch (\ValueError $e) {
  25. echo $e->getMessage(), \PHP_EOL;
  26. }
  27. try {
  28. $converted = pg_insert($db, $table_name, ['AAA']);
  29. } catch (\ValueError $e) {
  30. echo $e->getMessage(), \PHP_EOL;
  31. }
  32. try {
  33. $converted = pg_insert($db, $table_name, ['num' => []]);
  34. } catch (\TypeError $e) {
  35. echo $e->getMessage(), \PHP_EOL;
  36. }
  37. try {
  38. $converted = pg_insert($db, $table_name, ['num' => new stdClass()]);
  39. } catch (\TypeError $e) {
  40. echo $e->getMessage(), \PHP_EOL;
  41. }
  42. try {
  43. $converted = pg_insert($db, $table_name, ['num' => $db]);
  44. var_dump($converted);
  45. } catch (\TypeError $e) {
  46. echo $e->getMessage(), \PHP_EOL;
  47. }
  48. echo "Ok\n";
  49. ?>
  50. --EXPECTF--
  51. INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
  52. INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
  53. object(PgSql\Result)#%d (0) {
  54. }
  55. Array of values must be an associative array with string keys
  56. Array of values must be an associative array with string keys
  57. Values must be of type string|int|float|bool|null, array given
  58. Values must be of type string|int|float|bool|null, stdClass given
  59. Values must be of type string|int|float|bool|null, PgSql\Connection given
  60. Ok