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:
Wez Furlong 2004-09-19 19:28:02 +00:00
parent f40608230b
commit ceb551024a

View file

@ -166,11 +166,26 @@ static PHP_FUNCTION(dbh_constructor)
colon = strchr(data_source, ':');
if (!colon) {
/* 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)) {
/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source, alt_dsn, sizeof(alt_dsn) TSRMLS_CC);