من الممكن استخدام متعددة/المتداخلة MySQLi التصريحات ؟
سؤال
هل من الممكن أن يكون MySQLi prepared statement
داخل fetch()
دعوة من العبارة السابقة ؟ إذا لم يكن كذلك ، ما هي أفضل طريقة للتغلب على ذلك ؟
رمز المثال:
if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) {
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($item);
while( $stmt->fetch() ) {
/* Other code here */
$itemSummary = $item + $magic;
if($stmt2 = $link->prepare("INSERT INTO summaries (itemID, summary) VALUES (?, ?)")) {
$stmt2->bind_param("is", $itemID, $itemSummary);
$stmt2->execute();
$stmt2->close();
}
}
}
المحلول
يجب أن تكون قادرة على القيام بذلك ، على الرغم من أن لديهم لبدء اتصال ثاني.
نصائح أخرى
هذا هو واحد طريقة الاتصال:
if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) {
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->store_result(); // <-- this
$stmt->bind_result($item);
while( $stmt->fetch() ) {
/* Other code here */
$itemSummary = $item + $magic;
if($stmt2 = $link->prepare("INSERT INTO summaries (itemID, summary) VALUES (?, ?)")) {
$stmt2->bind_param("is", $itemID, $itemSummary);
$stmt2->execute();
$stmt2->store_result(); // <-- this
/*DO WHATEVER WITH STMT2*/
$stmt2->close();
}
}
}
أو استخدام store_result
.
لا تنتمي إلى StackOverflow