From ceb551024a576f03ee6964eb22116ccb405ef27c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 19 Sep 2004 19:28:02 +0000 Subject: [PATCH] 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. --- ext/pdo/pdo_dbh.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 82e04548d3..18041c39db 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -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)) { -- 2.50.1