我有一个简单的 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'"
从查询来看,工作正常。
最佳答案
检查
连接
$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)
关于php - 查询将直接在 MySQL 上运行,而不是通过 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31829614/