i have been using codeigniter active record class for database acces, But one thing i want to assure is the database security. My scenario is: I am using this query to access data from database.
$q = $this->db->query("SELECT* FROM mytable WHERE id = '$p'");
After this i use return statement.
return $q->result();
when i load database to my view i encode the array with the json encode function and the json encode function not only shows the value of database table fields but also the table field names.
Is it secure or if not how can i avoid displaying table field names
thanks.
You can strip the table field names by changing your return statement to:
Better ways would be to parse the results:
or specify which columns you need in the SQL statement in case the schema changes:
Finally, as allen213 mentioned, you should use bindings to prevent injection attacks: