Mar*_*rky 1 php postgresql json
我有一个奇怪的问题.我需要向客户端发送一些代码,而无需访问服务器来测试我的代码.另外,它使用的是我从未使用过的postgreSQL,而且我还没有使用PHP一段时间!
为了节省一些时间,如果有人能告诉我这段代码是否符合我的要求,我真的很感激?
<?
$sql = "SELECT * FROM V_SIDE_MENU_E";
include 'db.inc.php';
?>
Run Code Online (Sandbox Code Playgroud)
$connectString = 'host=localhost dbname=myDatabase user=foo password=bar';
$link = pg_connect($connectString);
if (!$link) {
echo "error";
} else {
$result = pg_query($link, $sql);
$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows);
}
Run Code Online (Sandbox Code Playgroud)
我会改变
$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows);
Run Code Online (Sandbox Code Playgroud)
成
print json_encode(array_values(pg_fetch_all($result)));
Run Code Online (Sandbox Code Playgroud)
但这只是一种风格 - 你的代码应该有效.
| 归档时间: |
|
| 查看次数: |
2173 次 |
| 最近记录: |