Skip to content

Commit 1360664

Browse files
Copilotsstidl
andauthored
Fix SQLite database path to resolve "unable to open database file" error (#736)
* Initial plan * Fix SQLite database path and add write permission checks - Changed default SQLite database path from '../../speedtest_telemetry.sql' to '__DIR__/speedtest_telemetry.db' to keep it within the results directory - Added directory existence and writability checks with helpful error messages - Added SQLite database files to .gitignore to prevent committing user data Co-authored-by: sstidl <[email protected]> * Fix indentation to use tabs consistently in telemetry_db.php Co-authored-by: sstidl <[email protected]> * Remove temporary backup file --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sstidl <[email protected]>
1 parent a3ed066 commit 1360664

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ db-dir/
44
.vscode/
55
node_modules/
66
package-lock.json
7+
results/speedtest_telemetry.db
8+
results/speedtest_telemetry.db-shm
9+
results/speedtest_telemetry.db-wal

results/telemetry_db.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ function getPdo($returnErrorMessage = false)
104104
return false;
105105
}
106106

107+
// Check if directory exists and is writable
108+
$db_dir = dirname($Sqlite_db_file);
109+
if (!is_dir($db_dir)) {
110+
if ($returnErrorMessage) {
111+
return "SQLite database directory does not exist: " . $db_dir . ". Please create it and ensure it's writable by the web server.";
112+
}
113+
return false;
114+
}
115+
if (!is_writable($db_dir)) {
116+
if ($returnErrorMessage) {
117+
return "SQLite database directory is not writable: " . $db_dir . ". Please ensure the web server has write permissions (e.g., chmod 755 or 775).";
118+
}
119+
return false;
120+
}
121+
107122
$pdo = new PDO('sqlite:'.$Sqlite_db_file, null, null, $pdoOptions);
108123

109124
# TODO: Why create table only in sqlite mode?

results/telemetry_settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
// Type of db: "mssql", "mysql", "sqlite" or "postgresql"
4-
$db_type = 'mysql';
4+
$db_type = 'sqlite';
55
// Password to login to stats.php. Change this!!!
66
$stats_password = 'PASSWORD';
77
// If set to true, test IDs will be obfuscated to prevent users from guessing URLs of other tests
@@ -10,7 +10,7 @@
1010
$redact_ip_addresses = false;
1111

1212
// Sqlite3 settings
13-
$Sqlite_db_file = '../../speedtest_telemetry.sql';
13+
$Sqlite_db_file = __DIR__ . '/speedtest_telemetry.db';
1414

1515
// mssql settings
1616
$MsSql_server = 'DB_HOSTNAME';

0 commit comments

Comments
 (0)