public static Connection::open(array &$connection_options = array())
Opens a PDO connection.
Parameters
array $connection_options: The database connection settings array.
Return value
\PDO A \PDO object.
Overrides Connection::open
File
- core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php, line 77
Class
- Connection
- PostgreSQL implementation of \Drupal\Core\Database\Connection.
Namespace
Drupal\Core\Database\Driver\pgsql
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | public static function open( array & $connection_options = array ()) { // Default to TCP connection on port 5432. if ( empty ( $connection_options [ 'port' ])) { $connection_options [ 'port' ] = 5432; } // PostgreSQL in trust mode doesn't require a password to be supplied. if ( empty ( $connection_options [ 'password' ])) { $connection_options [ 'password' ] = NULL; } // If the password contains a backslash it is treated as an escape character // so backslashes in the password need to be doubled up. // The bug was reported against pdo_pgsql 1.0.2, backslashes in passwords // will break on this doubling up when the bug is fixed, so check the version //elseif (phpversion('pdo_pgsql') < 'version_this_was_fixed_in') { else { $connection_options [ 'password' ] = str_replace ( '\\' , '\\\\' , $connection_options [ 'password' ]); } $connection_options [ 'database' ] = (! empty ( $connection_options [ 'database' ]) ? $connection_options [ 'database' ] : 'template1' ); $dsn = 'pgsql:host=' . $connection_options [ 'host' ] . ' dbname=' . $connection_options [ 'database' ] . ' port=' . $connection_options [ 'port' ]; // Allow PDO options to be overridden. $connection_options += array ( 'pdo' => array (), ); $connection_options [ 'pdo' ] += array ( \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, // Prepared statements are most effective for performance when queries // are recycled (used several times). However, if they are not re-used, // prepared statements become inefficient. Since most of Drupal's // prepared queries are not re-used, it should be faster to emulate // the preparation than to actually ready statements for re-use. If in // doubt, reset to FALSE and measure performance. \PDO::ATTR_EMULATE_PREPARES => TRUE, // Convert numeric values to strings when fetching. \PDO::ATTR_STRINGIFY_FETCHES => TRUE, ); $pdo = new \PDO( $dsn , $connection_options [ 'username' ], $connection_options [ 'password' ], $connection_options [ 'pdo' ]); return $pdo ; } |
Please login to continue.