Reputation: 109
I try to insert array into my database. but before that I gt an error :
Call to undefined method mysqli::mysqli_escape_string()
my code as follow:
if(!empty($img_src)){
$img_src = $db->mysqli_escape_string(serialize($img_src));
$stmt2 = $db->prepare("INSERT INTO photo_upload(`post_id`,`img_src`) VALUES (?,?)");
$stmt2->bind_param('is', mysqli_insert_id($db),$img_src);
$stmt2->execute();
}
Upvotes: 1
Views: 6377
Reputation: 164796
You don't need to escape $img_src
if you're using it with bind_param
. You'll also have to save mysqli_insert_id($db)
into a variable to use it in bind_param
as all arguments after the first are passed by reference. Or simply use $db->insert_id
...
if(!empty($img_src)){
$img_src = serialize($img_src);
$stmt2 = $db->prepare("INSERT INTO photo_upload(`post_id`,`img_src`) VALUES (?,?)");
if (!$stmt2) {
throw new Exception($db->error, $db->errno);
}
$stmt2->bind_param('is', $db->insert_id, $img_src);
if (!$stmt2->execute()) {
throw new Exception($stmt2->error, $stmt2->errno);
}
}
Upvotes: 0