summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/sqlite_driver.c
diff options
context:
space:
mode:
authortzmfreedom <makoto_tajitsu@hotmail.co.jp>2021-01-17 14:13:19 +0900
committerNikita Popov <nikita.ppv@gmail.com>2021-01-25 14:44:56 +0100
commita8dd009f23ab9ccd6b63f58a203d49fd0513a50d (patch)
tree3d4b678190557ce2bd602856b3e4af2e490f3d82 /ext/pdo_sqlite/sqlite_driver.c
parentcc3e03c5122b1639e0bcca60f8bcf597605568ad (diff)
downloadphp-git-a8dd009f23ab9ccd6b63f58a203d49fd0513a50d.tar.gz
Allow specifying sqlite3 DSN (file:/) in PDO SQLite
Closes GH-6610.
Diffstat (limited to 'ext/pdo_sqlite/sqlite_driver.c')
-rw-r--r--ext/pdo_sqlite/sqlite_driver.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c
index a48c77f9e8..217833f6ad 100644
--- a/ext/pdo_sqlite/sqlite_driver.c
+++ b/ext/pdo_sqlite/sqlite_driver.c
@@ -731,6 +731,12 @@ static const struct pdo_dbh_methods sqlite_methods = {
static char *make_filename_safe(const char *filename)
{
+ if (*filename && strncasecmp(filename, "file:", 5) == 0) {
+ if (PG(open_basedir) && *PG(open_basedir)) {
+ return NULL;
+ }
+ return estrdup(filename);
+ }
if (*filename && memcmp(filename, ":memory:", sizeof(":memory:"))) {
char *fullpath = expand_filepath(filename, NULL);
@@ -803,6 +809,9 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{
flags = pdo_attr_lval(driver_options, PDO_SQLITE_ATTR_OPEN_FLAGS, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ if (!(PG(open_basedir) && *PG(open_basedir))) {
+ flags |= SQLITE_OPEN_URI;
+ }
i = sqlite3_open_v2(filename, &H->db, flags, NULL);
efree(filename);