gpt4 book ai didi

php - 在 MYSQL 语句中连接 PHP 变量 DATETIME

转载 作者:行者123 更新时间:2023-11-29 19:17:43 25 4
gpt4 key购买 nike

我从 Datepicker Jquery UI 获取 DATE 变量,并将其作为变量包含在 MYSQL 语句中。但 select 不适用于该变量。什么原因?

代码下方

$fromDate = new DateTime($from);
$toDate = new DateTime($to);

$fromDate2 = mysqli_real_escape_string($fromDate);
$toDate2 = mysqli_real_escape_string($toDate);

$sql = mysqli_query($mySqlConnect,"SELECT * FROM 1398_log WHERE date BETWEEN $fromDate2 AND $toDate2 ORDER by id DESC");

这里选择确定:

$sql = mysqli_query($mySqlConnect,"SELECT * FROM 1398_log WHERE date BETWEEN '2016-03-01 00:00:00' AND  '2016-06-30 23:59:59'ORDER by id DESC");

最佳答案

您需要在 sql 中以字符串形式提供日期:

$sql = mysqli_query($mySqlConnect,"SELECT * 
FROM 1398_log
WHERE date BETWEEN '$fromDate2' AND '$toDate2'
ORDER by id DESC");

观看“

关于php - 在 MYSQL 语句中连接 PHP 变量 DATETIME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42617034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com