I am in the process of trying to figure out how PDO_MySQL works, and converting my mysql queries over to it.
Currently, I have the following code to check if rows were returned in a query:
if ($result->num_rows > 0) {
I tried changing this over to PDO by using the following references:
$sql=“select * from tableCategories;”;
$result = $pdo->query($sql);
$result->setFetchMode(PDO::FETCH_ASSOC);
if ($result->fetchColumn() > 0) {
while($row = $result->fetch()) {
This does retrieve the data needed, however the first row of data is not captured. I am fairly certain it is related to the IF statement, but I don’t know why. Why is this? I tried changing the value of 0 to -1, but that didn’t help.
(Note: I have stripped the page specific code in between all the references – there is data that displays in between the IF and the WHILE, so both are needed).