我想使用Doctrine做一个准备好的SQL语句。 如果我硬编码在SQL查询它的工作的价值:为什么我得到一个PDOException:SQLSTATE [42000]
public function search()
{
$sql = 'SELECT `name` FROM `files` WHERE `name` = "myfile.exe"';
$query = $this->conn->prepare($sql);
$status = $query->execute();
$searchResult = $query->fetchAll();
$searchResult = array(
'service' => $searchResult,
'status' => $status
);
$searchResult = $this->conn->fetchAll($sql);
return $searchResult;
}
但是,如果我试图用一个参数传递值不中,给我的PDOException:SQLSTATE [42000]
public function search()
{
$sql = 'SELECT `name` FROM `files` WHERE `name` = :service';
$query = $this->conn->prepare($sql);
$query->bindValue(":service", "myfile.exe");
$status = $query->execute();
$searchResult = $query->fetchAll();
$searchResult = array(
'service' => $searchResult,
'status' => $status
);
$searchResult = $this->conn->fetchAll($sql);
return $searchResult;
}
我无法弄清楚我做错了什么。在文档http://doctrine-orm.readthedocs.io/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html
您是否尝试过直接从MySQL命令行运行sql语句来查看是否有效?此外,这是纯粹的学说代码,还是使用Laravel或Symfony之类的PHP框架? –