I am trying to echo all the values of 'comment' from a user defined table ($table_name
)
$pdo = new PDO('mysql:dbname=db', 'user', 'pass');
$stmt2 = $pdo->query("SELECT comment FROM '$table_name'");
if ($stmt2->rowCount() > 0) {
$comments = $stmt2->fetchAll(PDO::FETCH_NUM);
foreach ($comments as $comment) {
$comm = $comment[0];
echo $comm;
}
}
However I get this error:
Fatal error: Call to a member function rowCount() on a non-object in /FilePath/file.php on line 3