Advertisement
Guest User

Untitled

a guest
May 8th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <?php
  2. require_once 'class.sql_pool.php';
  3.  
  4. class sql_pool_pdo extends PropelPDO {
  5.  
  6. /**
  7. * Construct a new sql_pool_pdo connection.
  8. *
  9. * This method is overridden in order to specify a custom PDOStatement class.
  10. *
  11. * @param string $dsn Connection DSN
  12. * @param string $username (optional
  13. * @param string $password
  14. * @param array $driver_options
  15. * @throws PDOException - if there is an error during connection initialization
  16. */
  17. public function __construct($dsn, $username = null, $password = null, $driver_options = array())
  18. {
  19. error_log("dsn1:$dsn; username=$username; password=$password; opts=".print_r($driver_options,1));
  20.  
  21. list($prefix, $props) = explode(':', $dsn, 2);
  22. if ($prefix == 'sql_pool') {
  23. // for sql_pool we rewrite $dsn whatever it gives us
  24. $schema = null;
  25. foreach (explode(';', $props) as $prop) {
  26. list($key, $value) = explode('=', $prop, 2);
  27. if ($key == 'schema') {
  28. $schema = $value;
  29. break;
  30. }
  31. }
  32. if (is_null($schema)) {
  33. throw new PropelException("No schema found from dsn: " . $dsn. ": Check your configuration file");
  34. }
  35.  
  36. $props = sql_pool::get_schema($schema);
  37. $dsn = 'mysql:dbname='.$props['dbname'];
  38. if ($props['host']) {
  39. $dsn .= ';host='.$props['host'];
  40. }
  41. if ($props['port']) {
  42. $dsn .= ';port='.$props['port'];
  43. }
  44. if ($props['socket']) {
  45. $dsn .= ';unix_socket='.$props['socket'];
  46. }
  47. $username = $props['user'];
  48. $password = $props['pass'];
  49. }
  50.  
  51. error_log("dsn2:$dsn; username=$username; password=$password; opts=".print_r($driver_options,1));
  52.  
  53. parent::__construct($dsn, $username, $password, $driver_options);
  54. }
  55.  
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement