]> granicus.if.org Git - php/commitdiff
Add support for:
authorWez Furlong <wez@php.net>
Sun, 19 Sep 2004 19:28:02 +0000 (19:28 +0000)
committerWez Furlong <wez@php.net>
Sun, 19 Sep 2004 19:28:02 +0000 (19:28 +0000)
$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

index 82e04548d31f3fea270f18e759ce190a00101d26..18041c39dbd311dedb6f58be91a9e36ccbb92fe0 100755 (executable)
@@ -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)) {