18pg_escape_bytea_esc.phpt 678 B

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