10pg_convert_9.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. PostgreSQL pg_convert() (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. $converted = pg_convert($db, $table_name, $fields);
  18. var_dump($converted);
  19. /* Invalid values */
  20. try {
  21. $converted = pg_convert($db, $table_name, [5 => 'AAA']);
  22. } catch (\ValueError $e) {
  23. echo $e->getMessage(), \PHP_EOL;
  24. }
  25. try {
  26. $converted = pg_convert($db, $table_name, ['AAA']);
  27. } catch (\ValueError $e) {
  28. echo $e->getMessage(), \PHP_EOL;
  29. }
  30. try {
  31. $converted = pg_convert($db, $table_name, ['num' => []]);
  32. } catch (\TypeError $e) {
  33. echo $e->getMessage(), \PHP_EOL;
  34. }
  35. try {
  36. $converted = pg_convert($db, $table_name, ['num' => new stdClass()]);
  37. } catch (\TypeError $e) {
  38. echo $e->getMessage(), \PHP_EOL;
  39. }
  40. try {
  41. $converted = pg_convert($db, $table_name, ['num' => $db]);
  42. var_dump($converted);
  43. } catch (\TypeError $e) {
  44. echo $e->getMessage(), \PHP_EOL;
  45. }
  46. ?>
  47. --EXPECT--
  48. array(3) {
  49. [""num""]=>
  50. string(4) "1234"
  51. [""str""]=>
  52. string(6) "E'AAA'"
  53. [""bin""]=>
  54. string(12) "E'\\x424242'"
  55. }
  56. Array of values must be an associative array with string keys
  57. Array of values must be an associative array with string keys
  58. Values must be of type string|int|float|bool|null, array given
  59. Values must be of type string|int|float|bool|null, stdClass given
  60. Values must be of type string|int|float|bool|null, PgSql\Connection given