소스 검색

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 <12804296+sstidl@users.noreply.github.com>

* Fix indentation to use tabs consistently in telemetry_db.php

Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>

* Remove temporary backup file

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sstidl <12804296+sstidl@users.noreply.github.com>
Copilot 7 달 전
부모
커밋
1360664796
3개의 변경된 파일20개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      .gitignore
  2. 15 0
      results/telemetry_db.php
  3. 2 2
      results/telemetry_settings.php

+ 3 - 0
.gitignore

@@ -4,3 +4,6 @@ db-dir/
 .vscode/
 node_modules/
 package-lock.json
+results/speedtest_telemetry.db
+results/speedtest_telemetry.db-shm
+results/speedtest_telemetry.db-wal

+ 15 - 0
results/telemetry_db.php

@@ -104,6 +104,21 @@ function getPdo($returnErrorMessage = false)
                 return false;
             }
 
+			// Check if directory exists and is writable
+			$db_dir = dirname($Sqlite_db_file);
+			if (!is_dir($db_dir)) {
+				if ($returnErrorMessage) {
+					return "SQLite database directory does not exist: " . $db_dir . ". Please create it and ensure it's writable by the web server.";
+				}
+				return false;
+			}
+			if (!is_writable($db_dir)) {
+				if ($returnErrorMessage) {
+					return "SQLite database directory is not writable: " . $db_dir . ". Please ensure the web server has write permissions (e.g., chmod 755 or 775).";
+				}
+				return false;
+			}
+
             $pdo = new PDO('sqlite:'.$Sqlite_db_file, null, null, $pdoOptions);
 
             # TODO: Why create table only in sqlite mode?

+ 2 - 2
results/telemetry_settings.php

@@ -1,7 +1,7 @@
 <?php
 
 // Type of db: "mssql", "mysql", "sqlite" or "postgresql"
-$db_type = 'mysql';
+$db_type = 'sqlite';
 // Password to login to stats.php. Change this!!!
 $stats_password = 'PASSWORD';
 // If set to true, test IDs will be obfuscated to prevent users from guessing URLs of other tests
@@ -10,7 +10,7 @@ $enable_id_obfuscation = false;
 $redact_ip_addresses = false;
 
 // Sqlite3 settings
-$Sqlite_db_file = '../../speedtest_telemetry.sql';
+$Sqlite_db_file = __DIR__ . '/speedtest_telemetry.db';
 
 // mssql settings
 $MsSql_server = 'DB_HOSTNAME';