Advertisement
Guest User

Untitled

a guest
May 13th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. $router = new protectclassesRouter();
  2. $tmp = serialize($router);
  3.  
  4. $dsn = 'pgsql:dbname=system;host=127.0.0.1';
  5. $user = 'postgres';
  6. $password = 'mypassword';
  7. $pdo = new PDO($dsn, $user, $password, $options);
  8. $pdo->exec('SET search_path = temporary');
  9. $pdo->query("SELECT replace_value('protectclassesRouter','$tmp','serialized_classes')"); // this is my function it`s work fine
  10.  
  11. $tmp = addslashes(serialize($router));
  12.  
  13. $sth = $pdo->prepare('SELECT replace_value(?, ?, ?)');
  14. $sth->execute(array('protectclassesRouter', $tmp, 'serialized_classes'));
  15.  
  16. $sth = $pdo->prepare('SELECT replace_value(:router, :serialbytes, :mode)');
  17. $sth->bindParam(':router', 'protectclassesRouter');
  18. $sth->bindParam(':mode', 'serialized_classes');
  19. $sth->bindParam(':serialbytes', $tmp, PDO::PARAM_LOB);
  20. $sth->execute();
  21.  
  22. use ZendSerializerAdapterPhpSerialize;
  23.  
  24. /**
  25. *
  26. * Class overloads serialization methods so serialized objects will be PostgreSQL safe
  27. * For further information on safe/unsafe objects:
  28. * http://php.net/manual/en/function.serialize.php#96504
  29. *
  30. */
  31. class PostgresSerialize extends PhpSerialize {
  32.  
  33. const DEFAULT_SAFE_NULLBYTE_REPLACEMENT = "~~NULL_BYTE~~";
  34.  
  35. protected static $serializedFalse = null;
  36.  
  37. public function serialize($value) {
  38. $serializedString = parent::serialize($value);
  39. if (strpos($this->options['safe_nullbyte_replacement'], $serializedString))
  40. throw new RuntimeException('Cannot perform safe nullbyte replace operation since safe_nullbyte_replacement="' . $this->options['safe_nullbyte_replacement'] . '"value already exists in the serialized string', ZendLogLogger::ERR);
  41. if ($this->options['safe_nullbyte_replacement'] == null)
  42. $this->options['safe_nullbyte_replacement'] = self::DEFAULT_SAFE_NULLBYTE_REPLACEMENT;
  43. return str_replace("", $this->options['safe_nullbyte_replacement'], $serializedString);
  44. }
  45.  
  46. public function unserialize($serialized) {
  47. if ($this->options['safe_nullbyte_replacement'] == null)
  48. $this->options['safe_nullbyte_replacement'] = self::DEFAULT_SAFE_NULLBYTE_REPLACEMENT;
  49. $serializedString = str_replace($this->options['safe_nullbyte_replacement'], "", $serialized);
  50. return parent::unserialize($serializedString);
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement