diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2004-07-29 00:18:02 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2004-07-29 00:18:02 +0000 |
| commit | 65ae35729d980344eeec809440414f5629d2ae6a (patch) | |
| tree | 2343f1228a5f55ee3d572d18cb2e5e2ffce7dd6e /ext/pdo_pgsql | |
| parent | 45ddc6a5cdb60884852d6cd206ffdd36fe9bcab5 (diff) | |
| download | php-git-65ae35729d980344eeec809440414f5629d2ae6a.tar.gz | |
Proper parameter separators for PostgreSQL connection initialization.
Diffstat (limited to 'ext/pdo_pgsql')
| -rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index f6c08cf863..f30b39ecc8 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -317,7 +317,7 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ { pdo_pgsql_db_handle *H; int ret = 0; - char *conn_str; + char *conn_str, *p, *e; H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent); dbh->driver_data = H; @@ -325,15 +325,24 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ H->einfo.errcode = 0; H->einfo.errmsg = NULL; + /* PostgreSQL wants params in the connect string to be separated by spaces, + * if the PDO standard semicolons are used, we convert them to spaces + */ + e = (char *) dbh->data_source + strlen(dbh->data_source); + p = (char *) dbh->data_source; + while ((p = memchr(p, ';', (e - p)))) { + *p = ' '; + } + /* support both full connection string & connection string + login and/or password */ if (!dbh->username || !dbh->password) { conn_str = (char *) dbh->data_source; } else if (dbh->username && dbh->password) { - spprintf(&conn_str, 0, "%s;user=%s;password=%s", dbh->data_source, dbh->username, dbh->password); + spprintf(&conn_str, 0, "%s user=%s password=%s", dbh->data_source, dbh->username, dbh->password); } else if (dbh->username) { - spprintf(&conn_str, 0, "%s;user=%s", dbh->data_source, dbh->username); + spprintf(&conn_str, 0, "%s user=%s", dbh->data_source, dbh->username); } else { - spprintf(&conn_str, 0, "%s;password=%s", dbh->data_source, dbh->password); + spprintf(&conn_str, 0, "%s password=%s", dbh->data_source, dbh->password); } H->server = PQconnectdb(dbh->data_source); |
