Simple PDO question

In this code I have an echo line commented out, If I uncomment it I don’t get any results. I read somewhere that PDO objects are temporary. Does that mean once you use it you loose it?


$q = "SELECT COUNT(*) AS numrows FROM dictionary WHERE Vendor=?";
$stmt = $db->prepare($q);
$stmt->execute(array($vendor));
//echo $stmt->fetchColumn();
if ($stmt->fetchColumn() > 0) {
	echo 'We have reults';
	$stmt = $db->prepare("SELECT id, Vendor, Attribute FROM dictionary WHERE Vendor=?");
	if ($stmt->execute(array($vendor))) {
			while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
			echo 'Obj '.$row->Attribute . "\
";
			echo '<pre>Array'; print_r($row); echo '</pre>';
			}
	 }
	 else {
	 echo 'oops';
	 }
}
else {
  print "No rows matched the query.";
}


Thanks for any input.

Thanks, that clears it up.

It’s not so much that the objects are temporary but that once you fetch something you can’t go back and fetch it again.


$stmt->execute(array($vendor));

$count = $stmt->fetchColumn();
echo "The count is: $count\
";

if ($count > 0) {