mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +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:
parent
f40608230b
commit
ceb551024a
1 changed files with 18 additions and 3 deletions
|
@ -166,9 +166,24 @@ static PHP_FUNCTION(dbh_constructor)
|
||||||
colon = strchr(data_source, ':');
|
colon = strchr(data_source, ':');
|
||||||
|
|
||||||
if (!colon) {
|
if (!colon) {
|
||||||
zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "invalid data source name");
|
/* let's see if this string has a matching dsn in the php.ini */
|
||||||
ZVAL_NULL(object);
|
char *ini_dsn = NULL;
|
||||||
return;
|
|
||||||
|
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)) {
|
if (!strncmp(data_source, "uri:", sizeof("uri:")-1)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue