note 75375 added to function.mysqli-prepare

From: Date: Fri, 25 May 2007 19:30:10 +0000
Subject: note 75375 added to function.mysqli-prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-126907@lists.php.net to get a copy of this message
It must be noted in the Description whether developers should call mysqli_stmt_close prior to executing mysqli_prepare again on the same statement variable. Example, Script A calls mysqli_stmt_close twice: <?php /* Script A -- We are already connected to the database */ $stmt = mysqli_prepare($link, "INSERT INTO table VALUES (?, ?, 100)"); /* Query 1 */ mysqli_stmt_bind_param($stmt, "si", $string, $integer); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); // CLOSE $stmt $stmt = mysqli_prepare($link, "INSERT INTO table VALUES ('PHP', ?, ?)"); /* Query 2 */ mysqli_stmt_bind_param($stmt, "ii", $integer, $code); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); // CLOSE $stmt /* Script A -- Continues on... */ ?> Next, we have Script B, calling mysqli_prepare again before issuing mysqli_stmt_close on the prior statement. <?php /* Script B -- We are already connected to the database */ $stmt = mysqli_prepare($link, "INSERT INTO table VALUES (?, ?, 100)"); /* Query 1 */ mysqli_stmt_bind_param($stmt, "si", $string, $integer); mysqli_stmt_execute($stmt); $stmt = mysqli_prepare($link, "INSERT INTO table VALUES ('PHP', ?, ?)"); /* Query 2 */ mysqli_stmt_bind_param($stmt, "ii", $integer, $code); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); // CLOSE $stmt /* Script B -- Continues on... */ ?> Which method is more efficient and should be used by developers? ---- Server IP: 69.39.81.135 Probable Submitter: 70.106.246.228 ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-prepare.php Edit -- https://master.php.net/note/edit/75375 Del: integrated -- https://master.php.net/note/delete/75375/integrated Del: useless -- https://master.php.net/note/delete/75375/useless Del: bad code -- https://master.php.net/note/delete/75375/bad+code Del: spam -- https://master.php.net/note/delete/75375/spam Del: non-english -- https://master.php.net/note/delete/75375/non-english Del: in docs -- https://master.php.net/note/delete/75375/in+docs Del: other reasons-- https://master.php.net/note/delete/75375 Reject -- https://master.php.net/note/reject/75375 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126907) next »