How can I add a row to array using PDO. Previously i did it like this $message = array('status' => 'ok'; But when I try to use this in PDO like this it does’t work
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->query($sql);
$employees = $stmt->fetchAll(PDO::FETCH_OBJ);
$employees['status'] = 'ok';
$employees = array($employees);
$dbh = null;
header('Content-Type: application/json');
echo '{"key":'. json_encode($employees) .'}';
}
Try
If you want to typecast
$employeesinto an array, you should be using