]> granicus.if.org Git - php/commitdiff
Add "no permission" error code.
authorWez Furlong <wez@php.net>
Sun, 19 Sep 2004 16:58:13 +0000 (16:58 +0000)
committerWez Furlong <wez@php.net>
Sun, 19 Sep 2004 16:58:13 +0000 (16:58 +0000)
Add a uri: psuedo driver; it specifies the name of a resource that contains,
as its first line, the actual data source to connect to.
The resource can be a local file, or it can be any resource for which PHP
has a wrapper.

// loads connection data from the file "myapp"
$d = new PDO('uri:myapp');

// lets say that public.db.com has a read-only db open for the public
// their connection data is also published via the web:
// (not so great to resolve this on each request though...)
$d = new PDO('uri:http://public.db.com/pdo-connection-data');

ext/pdo/TODO
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_driver.h

index 43da3fe9a68bab9ceccbed99dc53141b9014c33e..b30eab16c2f579cdf140a65729d020bce14125fe 100755 (executable)
@@ -14,7 +14,6 @@ Low-level:
 - LOB support via Streams API
 - persistent handles
 - iterator support
-- "lazy" fetch support
 
 Not-so-low-level:
 - hash key case folding for portabilitiy, ala sqlite.assoc_case, but not using an ini option.
index 23503a7303a5db5eba96b257ced4c4a8d59506cc..09a96c39bc70b07a608c24e59d44d88050240b85 100755 (executable)
@@ -63,6 +63,7 @@ void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC)
                case PDO_ERR_MISMATCH:                  msg = "Mismatch"; break;
                case PDO_ERR_TRUNCATED:                 msg = "Truncated"; break;
                case PDO_ERR_DISCONNECTED:              msg = "Disconnected"; break;
+               case PDO_ERR_NO_PERM:                   msg = "No permission"; break;
                default:        msg = "<<Invalid>>";
        }
 
@@ -126,6 +127,19 @@ void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC)
        }
 }
 
+static char *dsn_from_uri(char *uri TSRMLS_DC)
+{
+       php_stream *stream;
+       char *dsn = NULL;
+
+       stream = php_stream_open_wrapper(uri, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
+       if (stream) {
+               dsn = php_stream_get_line(stream, NULL, 0, NULL);
+               php_stream_close(stream);
+       }
+       return dsn;
+}
+
 /* {{{ proto object PDO::__construct(string dsn, string username, string passwd [, array driver_opts])
    */
 static PHP_FUNCTION(dbh_constructor)
@@ -156,6 +170,16 @@ static PHP_FUNCTION(dbh_constructor)
                return;
        }
 
+       if (!strncmp(data_source, "uri:", sizeof("uri:")-1)) {
+               /* the specified URI holds connection details */
+               data_source = dsn_from_uri(data_source TSRMLS_CC);
+               if (!data_source) {
+                       zend_throw_exception_ex(php_pdo_get_exception(), PDO_ERR_SYNTAX TSRMLS_CC, "invalid data source URI");
+                       ZVAL_NULL(object);
+                       return;
+               }
+       }
+
        driver = pdo_find_driver(data_source, colon - data_source);
 
        if (!driver) {
index 2acd860b92f5d2052f58cf91386727f8c61976d6..f80efd2d8fff161d7c387df4828a7148703ebb51 100755 (executable)
@@ -95,6 +95,7 @@ enum pdo_error_type {
        PDO_ERR_MISMATCH,
        PDO_ERR_TRUNCATED,
        PDO_ERR_DISCONNECTED,
+       PDO_ERR_NO_PERM,
 };
 
 enum pdo_error_mode {