我有一个简单的MySQL查询
select * from tutor where verified = 0 and alert_by < '2015-08-05' LIMIT 0,1
现在,直接通过phpMyAdmin运行它会提供所需的结果,但是,当通过一组PHP语句执行此查询时,它不会返回任何内容。下面是我在PHP中的代码
$this_date = date("Y-m-d");
$query = "select * from tutor where verified = 0 and alert_by < '$this_date' LIMIT 0,1";
$contact = mysqli_query($conn, $query);
$row = $contact->fetch_array(MYSQLI_ASSOC);
然而,$row
是空的,我似乎无法弄清楚这一点。我知道这似乎微不足道,但它有点烦人。
注意:从查询中删除"and alert_by < '$this_date'"
,工作正常。
答案 0 :(得分:0)
检查
连接
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
像这样使用mysqli_query
$contact = mysqli_query($con,"select * from tutor where verified = 0 and alert_by < '$this_date' LIMIT 0,1");
像这样使用fetch array(示例#2程序风格)
$row = mysqli_fetch_array($contact, MYSQLI_ASSOC)