I'm using PDO in PHP to process MySQL tables. I want to get a row count of records returned to use in determining what further processing needs to be done. The code below will correctly display the number of rows returned, but I can't figure out a way to get the number into a variable.
This is a little more of the code:
Can anyone give me an idea of what might work? I'm kinda new to PDO.
Thanks,
Peter V.
Code:
[b][COLOR=red] echo 'There are ', $stmt->fetchColumn(), ' rows returned.<br>';[/color][/b]
This is a little more of the code:
Code:
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Uncomment this code to get record count.
$sql = 'Select COUNT(*) from MYAUTHORS INNER JOIN MYBOOKS USING (authorid)';
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':var1', $var1, PDO::PARAM_STR);
$stmt->execute();
echo 'There are ', $stmt->fetchColumn(), ' rows returned.<br>'; [COLOR=green] <= Does work [/color]
$rows = $stmt->fetchColumn(); [COLOR=red] <= doesn't work[/color]
echo "rows: $rows again <br>";
Thanks,
Peter V.