I'm trying to upgrade my old code with the new PDO code.
I used to have a generic function DoQuery($query);
in my main Class, say myclass, so i can call it simply from any page
like
$q = "select * from table where name = 'john' "
$result = $myclass->DoQuery($q); // returns an array i can loop
my current code is
function DoQuery($query, $assoc=0){
try {
$pdo = new PDO('mysql:host='.$this->sql["db_host"].';dbname='.$this->sql["db_data"], $this->sql["db_login"], $this->sql["db_pass"]);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $pdo->prepare($query);
$stmt->execute();
} catch(Exception $e) {//print error }
if ($assoc){
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
} else{
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
}
return $rows;
}
so i don't understand how do i safely escape the inputs if i have variable parameters (like 'name' in this case but can be whatever)?