I am trying to migrate from the old SQL method to the new PDO methods for dealing with database.
Here is what I have so far:
try{
$conn = new PDO(.......)//this code is working fine
$conn->exec("SET CHARACTER SET utf8");
$query = "INSERT INTO TABLE(name,username,password)VALUES(:name,:username,:password)";
$prepare_query = $conn->prepare($query);
$prepare_query->bindValue(':name',$name,PDO::PARAM_STR);
$prepare_query->bindValue(':username',$user,PDO::PARAM_STR);
$prepare_query->bindValue(':password',$pass,PDO::PARAM_STR);
$count = $conn->exec($prepare_query);//error is somewhere here
}catch(PDOException $e){
echo $e->getMessage();
}
if($count > 0) echo "done";
Now the error I am receiving is Warning: PDO::exec() expects parameter 1 to be string, object given in C:\xampp\htdocs\drug_center\includes\NewAccount.php on line 42.
I am a NEWBEE when it comes to the PDO methods. I have read this! but here it is not showing me how to prepare the statement. I want to protect my data base as much as possible. Can someone please explain where I have gone wrong and how to fix this?