Skip to content
Draft
9 changes: 7 additions & 2 deletions common/webapp/public/sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

// !!! SET YOUR SQL-CONNECTION SETTINGS HERE: !!!

$driver = 'mysql'; // 'mysql' (MySQL) or 'pgsql' (PostgreSQL)
$driver = 'mysql'; // 'mysql' (MySQL), 'pgsql' (PostgreSQL) or 'sqlite' (SQLite)
$sqlfile = 'bluemap.db'; // Only applies when using 'sqlite' as the driver
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for future self: This should probably specify it'll (most likely) require an absolute path instead of a relative path

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also specify that you'll need an extra driver on Windows for SQLite on PHP

$hostname = '127.0.0.1';
$port = 3306;
$username = 'root';
Expand Down Expand Up @@ -147,7 +148,11 @@ function send($data) {

// Initialize PDO
try {
$sql = new PDO("$driver:host=$hostname;port=$port;dbname=$database", $username, $password);
if ($driver === "sqlite") {
$sql = new PDO("$driver:file:$sqlfile?mode=ro");
} else {
$sql = new PDO("$driver:host=$hostname;port=$port;dbname=$database", $username, $password);
}
$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e ) {
error_log($e->getMessage(), 0); // Logs the detailed error message
Expand Down
Loading