Q&A
$stmt = null;
のようにプリペアドステートメントを削除するとはどういう意味なのですか?また、削除は必ずすべきことなのですか?
さらに$dbh = null;
のようにデータベースから切断は必ずすべきことですか?
ご教授よろしくお願いします。
php
1function add_review($product_id, $add_review, $dbh) { 2 3 // ユーザーidを代入 4 $user_id = $_SESSION['user_id']; 5 6 $sql = "INSERT INTO 7 reviews( 8 review_comment, 9 review_date, 10 review_product_id, 11 review_user_id 12 ) 13 VALUES ( 14 :review_comment, 15 :review_date, 16 :review_product_id, 17 :review_user_id 18 )"; 19 20 $stmt = $dbh->prepare($sql); 21 $stmt->bindValue(':review_comment', $add_review); 22 $stmt->bindValue(':review_date', date('Y-m-d H:i:s')); 23 $stmt->bindValue(':review_product_id', $product_id); 24 $stmt->bindValue(':review_user_id', $user_id); 25 $stmt->execute(); 26 27 // プリペアドステートメントを削除 28 $stmt = null; ←これについて 29 30 // 変数にリダイレクト先URLを格納する 31 $detail = $_SESSION['detail']; 32 $url = "http://localhost/bulletin/public/detail.php?id=" . $detail; 33 34 header("Location:" . $url ); 35 exit(); 36 37}
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。