SQL没有正确过滤某些条件

Tim*_*ych 0 php mysql sql

我的MySQL查询遇到了一些麻烦:

$statement = $conn->prepare
("SELECT * FROM ext where `approved` = 0 
and `account-type`= 2 
AND `ext-name` LIKE :search OR description LIKE :search");
Run Code Online (Sandbox Code Playgroud)

查询的LIKE部分有效 - 它确实返回与正确关键字对应的条目.但是,它返回的条目是每个account-type- 它不会过滤到只有account-type2 的条目.

我有一种感觉,这是我在使用SQL语句时出错了,但是如果它与我的PHP有关,那么这里是完整的代码片段:

    $statement = $conn->prepare("SELECT * FROM ext where `approved` = 0 and `account-type`= 2 AND `ext-name` LIKE :search OR description LIKE :search");
    $statement->bindValue(':search', "%{$keyword}%");
    $statement->execute();

    $exchanges = $statement->fetchAll();
Run Code Online (Sandbox Code Playgroud)

a1e*_*x07 7

使用括号:

SELECT * FROM ext 
where `approved` = 0 and `account-type`= 2 
AND (`ext-name` LIKE :search OR description LIKE :search)
Run Code Online (Sandbox Code Playgroud)