本文介绍了JSON的PDOStatement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将PDOStatement
转换为json?那里有图书馆吗?
How would I convert a PDOStatement
to json? Is there library out there to do this?
我需要对PDO::FETCH_OBJ
进行json化.抱歉,感谢您的答复.
I need to jsonify a PDO::FETCH_OBJ
. Sorry, thanks for all of the responses.
json_encode
无法对PDO::FETCH_OBJ
进行json加密.
json_encode
does not have the ability to jsonify a PDO::FETCH_OBJ
.
谢谢.
推荐答案
您可以使用内置的php函数json_encode() http://php.net/manual/zh-CN/function.json-encode.php
You can use the inbuilt php function json_encode() http://php.net/manual/en/function.json-encode.php
要对结果进行编码,请使用类似的
To encode the results use something like
<?php
$pdo = new PDO("mysql:dbname=database;host=127.0.0.1", "user", "password");
$statement = $pdo->prepare("SELECT * FROM table");
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
这篇关于JSON的PDOStatement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!