IS NOT NULL给出空值

时间:2016-02-05 18:20:49

标签: php sql pdo

我有使用PDO的以下PHP代码。我希望具有空值的行不会出现在结果中。我如何实现这一点,以及我在下面做错了什么?

<?php
require_once 'dbconfig.php';

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    echo "Connected to $dbname at $host successfully.";
    $sql = 'SELECT * 
            FROM as_questions 
            WHERE Answer IS NOT NULL';

    $q = $conn->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);

} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe->getMessage());
}

1 个答案:

答案 0 :(得分:1)

如上所述,两位人士(Fred -ii和Alex Anderi)请更改您的查询,如下所示: -

$sql = "SELECT * FROM as_questions WHERE Answer !=''";