im very new to PDO, can you please spot whats wrong with my code? im trying to insert a record into my mysql with an ARRAY.
this is my array
$myarray = array("id" =>'',
"title" =>$title,
"body" =>$body);
this is my function
function insertdata($myarray) {
$localhost = "localhost";
$user = "user";
$pass = "pass";
$dba = "sample";
$db = new PDO('mysql:host=$localhost;dbname=$dba', $user, $pass);
$sql=$db->prepare("INSERT INTO `posts`(`id`, `title`, `body`) VALUES (:id,:title,:body)");
foreach($myarray as $row=>$value) {
$sql->bindValue(":".$row,$value);
}
$sql->execute();
}