我对PDO很新,你能否发现我的代码有什么问题?我试图用ARRAY将记录插入我的mysql。
这是我的数组
$myarray = array("id" =>'',
"title" =>$title,
"body" =>$body);
这是我的功能
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();
}