I want to have a condition incase the row doesn\'t exist at all.
$stmt = $conn->prepare(\'SELECT * FROM table WHERE ID=?\');
$stmt->bindParam(1, $_GET[
if($stmt->rowCount() == 0)
should work fine, since the number of rows can't be less than zero in any event at all.
From the manual:
For most databases,
PDOStatement::rowCount()does not return the number of rows affected by aSELECTstatement. Instead, usePDO::query()to issue aSELECT COUNT(*)statement with the same predicates as your intendedSELECTstatement, then usePDOStatement::fetchColumn()to retrieve the number of rows that will be returned. Your application can then perform the correct action.
I would suggest reading up on that here.