I wanted to add all arrays from my database in one json encode and decode it later on.. but I ran into a thing which I don't know how to fix.
I'm trying to add all arrays from the sql query in one array and then encode that one array with all the arrays inside it.
My current code:
$dbh = new PDO('mysql:host='.$this->server.';dbname='.$this->database.'', $this->user, $this->pass);
$result = array();
foreach($dbh->query('SELECT * from bier') as $row) {
$result[] += $row;
}
print json_encode($result);
Updated code:
function getData()
{
try {
$dbh = new PDO('mysql:host='.$this->server.';dbname='.$this->database.'', $this->user, $this->pass);
$result = array();
foreach($dbh->query('SELECT * from bier') as $row) {
$result[] = $row;
}
$json = json_encode($result, JSON_PRETTY_PRINT);
var_dump($json);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
Currently returns: Boolean False