What is the save way to aviod SQL Injection.
I saw a lot of ways to build up the query my question is what is the safest way to avoid SQL-Injection.
INSERT 1
$st = $this->db->prepare("SELECT * FROM tbl WHERE name=? AND pass=?");
$st->bindParam(1, $name);
$st->bindParam(2, $pass);
$st->execute();
INSERT 2
$stmt = $this->db->prepare("INSERT INTO tbl VALUES(:id, :name)");
$stmt->bindValue(':id', $id);
$stmt->bindValue(':name', $name);
$stmt->execute();
Update 1
$st1 = $this->db->prepare("UPDATE tbl SET name=? WHERE name=?");
$st1->bindParam(1, $newname);
$st1->bindParam(2, $name);
$st1->execute();
SELECT
$st = $this->db->prepare("SELECT * FROM tbl WHERE name=?");
$st->bindParam(1, $name);
$st->execute();
Is it safer to use bindParam(1, $name)
or bindParam(:id, $name)
to avoid the SQL-Injections in the database?