18pg_escape_bytea_hex.phpt 694 B

123456789101112131415161718192021222324252627282930313233
  1. --TEST--
  2. PostgreSQL pg_escape_bytea() functions (hex format)
  3. --SKIPIF--
  4. <?php
  5. include("skipif.inc");
  6. skip_bytea_not_hex();
  7. ?>
  8. --FILE--
  9. <?php
  10. // optional functions
  11. include('config.inc');
  12. $db = pg_connect($conn_str);
  13. @pg_query($db, "SET bytea_output = 'hex'");
  14. $image = file_get_contents(dirname(__FILE__) . '/php.gif');
  15. $esc_image = pg_escape_bytea($image);
  16. pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
  17. $result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
  18. $rows = pg_fetch_all($result);
  19. $unesc_image = pg_unescape_bytea($rows[0]['bin']);
  20. if ($unesc_image !== $image) {
  21. echo "NG";
  22. }
  23. else {
  24. echo "OK";
  25. }
  26. ?>
  27. --EXPECT--
  28. OK