Skip to content

Commit 9f7c3f6

Browse files
Merge pull request #42 from kay0u/master
Fix some MySQL queries
2 parents bf5a336 + 58d60ae commit 9f7c3f6

File tree

1 file changed

+17
-4
lines changed
  • lxd-dashboard/backend/config

1 file changed

+17
-4
lines changed

lxd-dashboard/backend/config/db.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function initializeLogsTable(){
6565
}
6666

6767
if ($_SESSION['db_type'] == "MySQL"){
68-
$db->exec('CREATE TABLE IF NOT EXISTS lxd_logs (id INTEGER PRIMARY KEY AUTOINCREMENT, control VARCHAR(255), remote_id INTEGER, project VARCHAR(255), object VARCHAR(255), status_code INT, message VARCHAR(255), hostname VARCHAR(255), user_id INT, date DATE);');
68+
$db->exec('CREATE TABLE IF NOT EXISTS lxd_logs (id INTEGER PRIMARY KEY AUTO_INCREMENT, control VARCHAR(255), remote_id INTEGER, project VARCHAR(255), object VARCHAR(255), status_code INT, message VARCHAR(255), hostname VARCHAR(255), user_id INT, date DATE);');
6969
}
7070

7171
$db = null;
@@ -79,7 +79,7 @@ function initializePreferencesTable(){
7979
}
8080

8181
if ($_SESSION['db_type'] == "MySQL"){
82-
$db->exec('CREATE TABLE IF NOT EXISTS lxd_preferences (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(255), value VARCHAR(255));');
82+
$db->exec('CREATE TABLE IF NOT EXISTS lxd_preferences (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), value VARCHAR(255));');
8383
}
8484

8585
//Default Preferences
@@ -696,7 +696,14 @@ function addLogEvent($control, $remote_id, $project, $object, $status_code, $mes
696696
$db = establishDatabaseConnection();
697697

698698
try{
699-
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, datetime('now'));");
699+
$stmt = null;
700+
if ($_SESSION['db_type'] == "SQLite"){
701+
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, datetime('now'));");
702+
}
703+
704+
if ($_SESSION['db_type'] == "MySQL"){
705+
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, DATE(NOW()));");
706+
}
700707
$stmt->bindValue(':control', $control, PDO::PARAM_STR);
701708
$stmt->bindValue(':remote_id', $remote_id, PDO::PARAM_INT);
702709
$stmt->bindValue(':project', $project, PDO::PARAM_STR);
@@ -709,7 +716,13 @@ function addLogEvent($control, $remote_id, $project, $object, $status_code, $mes
709716
}
710717
catch ( PDOException $e ) {
711718
initializeAllTables();
712-
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, datetime('now'));");
719+
if ($_SESSION['db_type'] == "SQLite"){
720+
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, datetime('now'));");
721+
}
722+
723+
if ($_SESSION['db_type'] == "MySQL"){
724+
$stmt = $db->prepare("INSERT INTO lxd_logs (control, remote_id, project, object, status_code, message, hostname, user_id, date) VALUES (:control, :remote_id, :project, :object, :status_code, :message, :hostname, :user_id, DATE(NOW()));");
725+
}
713726
$stmt->bindValue(':control', $control, PDO::PARAM_STR);
714727
$stmt->bindValue(':remote_id', $remote_id, PDO::PARAM_INT);
715728
$stmt->bindValue(':project', $project, PDO::PARAM_STR);

0 commit comments

Comments
 (0)