且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 mysql_ 函数转换为 PDO

更新时间:2023-02-11 08:26:09

将代码转换为 PDO 是一项非常简单的任务.
您真正需要的唯一一件事就是阅读手册页上的示例(并理解它们).

To convert your code into PDO is quite a simple task.
The only thing you actually need is to read examples on the manual page (and to understand them).

由于您只需要关联数组形式的一行,fetch() 已经可以做到这一点.

As you need only one row in the form of associative array, fetch() can do that already.

$row=$sql->fetch(PDO::FETCH_ASSOC);
// The JSON standard MIME header.
header('Content-type: application/json');
echo  json_encode($row);