my php function returns following json object:
{"user_id":"1", "0":"1", "token":null, "1":null, "username":"bgarrett0", "2":"bgarrett0"}
it adding both numeric key/values , associative key/values. want associative/values. $sql prepared query string, args array of appropriate values $sql.
$this->pdo (mysql db) has attributes [pdo::attr_errmode, pdo::errmode_exception;pdo::attr_emulate_prepares, false;]
public function query($sql, $args) { try { $stmt = $this->pdo->prepare($sql); $stmt->execute($args); $stmt = $stmt->fetchall(); return json_encode($stmt); } catch(exception $e) { $this -> error_status = $e->getmessage(); } }
then use flag pdo::fetch_assoc
if want associative indices:
$data = $stmt->fetchall(pdo::fetch_assoc); return json_encode($data);