나는 내 mysql_query() 호출을 PDO로 변환하고 있지만, 을 얻는 방법을 이해하지 못하면 결과가 실패합니다.PDO 결과를 검색하는 방법 == false?
$STH = $DBH->query("SELECT * FROM articles ORDER BY category");
$STH->setFetchMode(PDO::FETCH_ASSOC);
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
이 내가 할 노력하고있어하지만 작동하지 않습니다 :
try
{
$STH = $DBH->prepare("SELECT * FROM articles ORDER BY category"); //Notice the prepare
$STH->setFetchMode(PDO::FETCH_ASSOC);
//No need to silent as the errors are catched.
if($STH === false) //Notice the explicit check with !==
{
//Do not run a foreach as its not multi-dimensional array
$Error = $DBH->errorInfo();
throw new Exception($Error[2]); //Driver Specific Error
}
}catch(Exception $e)
{
//An error accured of some nature, use $e->getMessage();
}
:
if($STH==false) {
foreach($dbh->errorInfo() as $error) {
echo $error.'<br />';
}
}
'false' 또는'true'로 특별히 작업 할 때는 항상 결과를 비교하기 위해'==='(= x3)을 사용해야합니다. – RobertPitt
@zerkms, 나는 또한 자바 스크립트 팀이'=='이 할 것이라고 생각한다. – RobertPitt