我曾经做过 :
$resource = mysql_query("SELECT * FROM table WHERE id = " . $id);
$user = mysql_fetch_assoc($resource);
echo "Hello User, your number is" . $user['number'];
我读到mysql语句已全部弃用,不应使用。
如何使用PDO做到这一点?
第一行是:
$stmt = $db->prepare("SELECT * FROM table WHERE id = " . $id); // there was an aditional double quote in here.
$stmt->execute(array(':id' => $id));
mysql_fetch_assoc()函数呢?
我正在使用php
最佳答案
您可以使用(PDO::FETCH_ASSOC)
常量
用法将是while ($res = $stmt->fetch(PDO::FETCH_ASSOC)){....}
这是参考(准确地是文档):http://www.php.net/manual/en/pdostatement.fetch.php