I know a standard query runs an SQL statement that requires all data to be escaped for safety, like preventing SQL injections.
And Prepared statements bind parameters where escaping data in not needed, and is ideal for queries that are being executed multiple times.
But I was wondering in terms of security and safety, what is the difference between these three query examples.
I know the first query ($query) with binding parameters is the safest and most ideal to use, but are the other two query examples ($query2 and $query3) also safe when using the CodeIgniter framework?
And if we just use php, is $query3 safe because the data variable its quoted?
Query 1
$query = "SELECT * FROM users WHERE id = ?";
$bind = array($id);
$query = $this->db->query($query, $bind);
Query 2
$query2 = "SELECT * FROM users WHERE id = '" . $this->db->escape_str($id) . "'";
Query 3
$query3 = "SELECT * FROM users WHERE id = '" . $id . "' ";