Reputation: 1314
I have a strange question. I need to send some code to a client without having access to the server to test my code. In addition, it's using postgreSQL which I've never used, and I've not done PHP for a while!
In order to save some time, I'd really appreciate if someone could tell me if this code will do what I want?
<?
$sql = "SELECT * FROM V_SIDE_MENU_E";
include 'db.inc.php';
?>
$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);
}
Upvotes: 1
Views: 2183
Reputation: 106549
I would change
$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode($rows);
into
print json_encode(array_values(pg_fetch_all($result)));
But that's just a style thing -- your code should work.
Upvotes: 6
Reputation: 25564
Tested on your mysql ( it looks like it will work ). Your SELECT will work same in PostgreSQL like mySQL
Upvotes: 2