Skip to content

Commit 58d60ae

Browse files
committed
fix MySQL date
1 parent 6d38fe8 commit 58d60ae

File tree

1 file changed

+15
-2
lines changed
  • lxd-dashboard/backend/config

1 file changed

+15
-2
lines changed

lxd-dashboard/backend/config/db.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)