我有一个包含 event_id 列和 schedule_at 列的数据库表。该查询在 php 中调用,如下所示:
$columnName = 'scheduled_at';
$start = '2013-02-26';
$end = '2013-02-27';
// query to be executed
$sql = ( SELECT * FROM $table WHERE $columnName BETWEEN $start AND $end );
执行时查询不起作用,但是以下确实有效
$sql = ( SELECT * FROM $table WHERE $columnName BETWEEN $start AND '2013-02-27' );
和
$sql = ( SELECT * FROM $table WHERE $columnName BETWEEN $start AND $start );
不工作,但以下工作
$sql = ( SELECT * FROM $table WHERE $columnName BETWEEN '2013-02-27' AND '2013-02-27' );
手动插入值使其工作,但失去了功能的用处。任何想法为什么它不起作用?