我曾经做过:
$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
关于php - mysql_fetch_assoc() 的 PDO 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16363794/