-2

I have some old code I want to be able to begin using again but it's in mysql and I'm not sure how to change the equivalent of this into PDO.

if(mysql_num_rows($result) > 0) {
        while($row = mysql_fetch_assoc($result)) {
            trackstart($row['ID']);
        }
    }       

How can I reach the same outcome with PDO? Or use while row = result for that matter

Henry D.
  • 41
  • 7
  • 1
    Funny; you have other questions with PDO code in there. Oh, and none of your questions have been marked as solved I might add. One of those that has a fetching method in PDO being https://stackoverflow.com/q/52589214/1415724 – Funk Forty Niner Oct 11 '18 at 13:59
  • Why is that funny? This is a different piece of code that I do not know how to turn into PDO unlike other parts. I'm only asking a question, if you don't want to answer then don't lol – Henry D. Oct 11 '18 at 14:02
  • You turned from PDO to mysql_ and then asking basically the same question. So yes, I find that "funny", but mostly questionable. There is a manual on this on php.net and the duplicate question that you consult. – Funk Forty Niner Oct 11 '18 at 14:03

1 Answers1

0

Translating your example should be something like:

$connection = new PDO('connection dsn', $user, $password);
$statement = $connection->prepare('SELECT * FROM table WHERE field = :value');
$statement->bindParam('value', $paramValue);
if ($statement->execute()) {
    while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
       trackstart($row['ID']);
    }
}
Gabriel Pereira
  • 160
  • 1
  • 10