$STH = $DBH -> prepare( "select * from table where id = :id" );
$STH -> bindParam( ':id', $_SESSION['id'], PDO::PARAM_INT, 4 );
$STH -> execute();
$result = $STH -> fetch();
if( isset( $result["id"] ) ) {
// do this if records are returned
} else {
// do this if no records are returned
}
if
由于某种原因,即使没有返回记录,语句的第一部分也会执行,为什么会发生这种情况?我假设这是因为isset
,但也不知道要改变什么?