查询将直接在MySQL上运行,但不能通过PHP运行

时间:2015-08-05 10:17:09

标签: php mysql

我有一个简单的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'",工作正常。

1 个答案:

答案 0 :(得分:0)

检查

  1. 连接

    $con = mysqli_connect("localhost","my_user","my_password","my_db");
    
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
  2. 像这样使用mysqli_query

    $contact = mysqli_query($con,"select * from tutor where verified = 0 and alert_by < '$this_date' LIMIT 0,1");
    
  3. 像这样使用fetch array示例#2程序风格

    $row = mysqli_fetch_array($contact, MYSQLI_ASSOC)