Skip to content

Commit 5e1a99e

Browse files
KalleZSjonHortensius
authored andcommitted
Extend PDO support for credentials in DSN to dblib/firebire/oci
1 parent d5748e7 commit 5e1a99e

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

ext/pdo_dblib/dblib_driver.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
375375
,{ "dbname", NULL, 0 }
376376
,{ "secure", NULL, 0 } /* DBSETLSECURE */
377377
,{ "version", NULL, 0 } /* DBSETLVERSION */
378+
,{ "user", NULL, 0 }
379+
,{ "password", NULL, 0 }
378380
};
379381

380382
nvars = sizeof(vars)/sizeof(vars[0]);
@@ -432,12 +434,20 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
432434
}
433435
}
434436

437+
if (!dbh->username && vars[6].optval) {
438+
dbh->username = vars[6].optval;
439+
}
440+
435441
if (dbh->username) {
436442
if(FAIL == DBSETLUSER(H->login, dbh->username)) {
437443
goto cleanup;
438444
}
439445
}
440446

447+
if (!dbh->password && vars[7].optval) {
448+
dbh->password = vars[7].optval;
449+
}
450+
441451
if (dbh->password) {
442452
if(FAIL == DBSETLPWD(H->login, dbh->password)) {
443453
goto cleanup;

ext/pdo_firebird/firebird_driver.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,24 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
617617
struct pdo_data_src_parser vars[] = {
618618
{ "dbname", NULL, 0 },
619619
{ "charset", NULL, 0 },
620-
{ "role", NULL, 0 }
620+
{ "role", NULL, 0 },
621+
{ "user", NULL, 0 },
622+
{ "password", NULL, 0 }
621623
};
622624
int i, ret = 0;
623625
short buf_len = 256, dpb_len;
624626

625627
pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent);
626628

627-
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 3);
629+
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 5);
630+
631+
if (!dbh->username && vars[3].optval) {
632+
dbh->username = vars[3].optval;
633+
}
634+
635+
if (!dbh->password && vars[4].optval) {
636+
dbh->password = vars[4].optval;
637+
}
628638

629639
do {
630640
static char const dpb_flags[] = {

ext/pdo_oci/oci_driver.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,12 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ *
591591
int i, ret = 0;
592592
struct pdo_data_src_parser vars[] = {
593593
{ "charset", NULL, 0 },
594-
{ "dbname", "", 0 }
594+
{ "dbname", "", 0 },
595+
{ "user", NULL, 0 },
596+
{ "password", NULL, 0 }
595597
};
596598

597-
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 2);
599+
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 4);
598600

599601
H = pecalloc(1, sizeof(*H), dbh->is_persistent);
600602
dbh->driver_data = H;
@@ -658,6 +660,10 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ *
658660
}
659661

660662
/* username */
663+
if (!dbh->username && vars[2].optval) {
664+
dbh->username = vars[2].optval;
665+
}
666+
661667
if (dbh->username) {
662668
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
663669
dbh->username, (ub4) strlen(dbh->username),
@@ -669,6 +675,10 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ *
669675
}
670676

671677
/* password */
678+
if (!dbh->password && vars[3].optval) {
679+
dbh->password = vars[3].optval;
680+
}
681+
672682
if (dbh->password) {
673683
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
674684
dbh->password, (ub4) strlen(dbh->password),

0 commit comments

Comments
 (0)