Possible Duplicate:
Are PDO prepared statements sufficient to prevent SQL injection?
my main concern with rolling out a new API Which I have been working on for a few days is the Security.
I'm a beginner to the PDO usage, but know the main structure. but I have no idea on how to protect the query from SQLInjection.
My code is Listed below:
<?php
$Start = new Db();
class Db
{
private $dbh = null;
public function __construct()
{
$this->dbh = new PDO('mysql:host=localhost;dbname=pdo', 'root', 'xxxxx');
}
public function PDOFetch($Var)
{
$sth = $this->dbh->prepare("$Var");
$sth->execute();
$result = $sth->fetchAll();
return $result;
}
public function PDONumb ($Var)
{
$sth = $this->dbh->prepare("$Var");
$sth->execute();
$count = $sth->rowCount();
return $count;
}
public function PDODel ($Var)
{
$Delete = $this->dbh->exec("$Var");
return $Delete;
}
public function PDOQuery ($Var)
{
$Query = $this->dbh->query("$Var");
return $Query;
}
}
?>
How would I go About protecting from SQL Injection and other vulnerabilities?
Edit:
Queries Being passed into the API is being done from the "index.php" page for example.
A line would be:
$Num = $Start->PDONumb("SELECT * FROM news");
But later, when I have covered my tracks with this. I want to go more advanced using this, so it will pass variables which user defines (hence the SQL injection question)
but at the moment, queries being passed through are defined by the administrator.