gpt4 book ai didi

php - SQL 查询不使用 php 变量

转载 作者:行者123 更新时间:2023-11-30 23:15:48 24 4
gpt4 key购买 nike

我的 Sql 查询返回空结果集。格式有没有错误。我在查询中使用了一些 php 变量..

public function getBlockDate($month,$year){
$connection = db::factory('mysql');
$time_from="00-00-00";
$time_to="23-59-59";
$sql = 'select * from blocks WHERE date LIKE "'.$year.'-'.$month.'%" AND (time_From="'.$time_from.'" AND time_to="'.$time_to.'")';

return $connection->getArray($sql);
}

*这里time_from和time_to表列是时间类型*

最佳答案

更改您的 SQL 查询

$sql = 'select * from blocks WHERE date LIKE "'.$year.'-'.$month.'%" AND (time_From="'.$time_from.'" AND time_to="'.$time_to.'")';

' $time_from$time_to 上缺少单引号

已编辑查询

$time_from="00:00:00";
$time_to="23:59:59";
$sql = 'select * from blocks WHERE date LIKE "'.$year.'-'.$month.'%" BETWEEN (time_From="'.$time_from.'" AND time_to="'.$time_to.'")';

同时将 - 更改为 : 在您的 $time_from$time_to 变量中

关于php - SQL 查询不使用 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17920873/

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