PDO method for mysql_fetch_assoc()?
database, mysql, pdo, php
Solution
You can use `(PDO::FETCH_ASSOC)` constant Usage will be `while ($res = $stmt->fetch(PDO::FETCH_ASSOC)){ .... }` Here's the reference (documentation precisely) : http://www.php.net/manual/en/pdostatement.fetch.php
Problem
I used to do : ``` $resource = mysql_query("SELECT * FROM table WHERE id = " . $id); $user = mysql_fetch_assoc($resource); echo "Hello User, your number is" . $user['number']; ``` I read that mysql statements are all deprecated and should not be used. How can i do this with PDO? The first line would be : ``` $stmt = $db->prepare("SELECT * FROM table WHERE id = " . $id); // there was an aditional double quote in here. $stmt->execute(array(':id' => $id)); ``` What about the mysql_fetch_assoc() function? I am using php