mirror of
https://github.com/php/php-src.git
synced 2026-04-02 21:52:36 +02:00
Add support for:
$d = new PDO('foobar'); // name has no : character
This will indirect via the entry "pdo.dsn.foobar" from the php.ini file,
so if you have:
pdo.dsn.foobar=sqlite::memory:
the above is equivalent to this:
$d = new PDO('sqlite::memory:');
which creates an in-memory sqlite db.
This commit is contained in:
@@ -166,9 +166,24 @@ static PHP_FUNCTION(dbh_constructor)
|
||||
colon = strchr(data_source, ':');
|
||||
|
||||
if (!colon) {
|
||||
zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "invalid data source name");
|
||||
ZVAL_NULL(object);
|
||||
return;
|
||||
/* let's see if this string has a matching dsn in the php.ini */
|
||||
char *ini_dsn = NULL;
|
||||
|
||||
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
|
||||
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) {
|
||||
zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "invalid data source name");
|
||||
ZVAL_NULL(object);
|
||||
return;
|
||||
}
|
||||
|
||||
data_source = ini_dsn;
|
||||
colon = strchr(data_source, ':');
|
||||
|
||||
if (!colon) {
|
||||
zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "invalid data source name (via INI: %s)", alt_dsn);
|
||||
ZVAL_NULL(object);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strncmp(data_source, "uri:", sizeof("uri:")-1)) {
|
||||
|
||||
Reference in New Issue
Block a user