1
我已經在這裏找到了很多答案,但是它們都不起作用。根據我的理解,第一個數據庫調用與第二個數據庫調用混淆了。但我認爲通過使用close()和unset()應該關閉第一個調用...準備失敗:(2014)命令不同步;你現在不能運行這個命令
任何想法?我需要從第一查詢結果,然後就行數爲第二個的...
//See if there are any sales that need printing
if ($stmt = $mysqli->prepare("SELECT quantity FROM sales WHERE printed = 0 AND DATE_FORMAT(saledatetime, '%Y/%m/%d') = ? AND venue = ?")) {
$stmt->bind_param('ss',$_SESSION['session_date'],str_replace(" ","",strtolower($_SESSION['venue'])));
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($qty);
$new = 0;
while($stmt->fetch()) {
$new = ($new + $qty);
}
//Close connection
$stmt->close();
unset($stmt);
}
//See if an upload has been done
if ($stmt = $mysqli->prepare("SELECT id FROM images WHERE udate = ? AND venue = ?")) {
$stmt->bind_param('ss',$_SESSION['session_date'],str_replace(" ","",strtolower($_SESSION['venue'])));
$stmt->execute();
$stmt->bind_result($imgs_tmp);
$rows = $stmt->num_rows;
}
編輯: 完整標題代碼
<?php
session_start();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//Make additional session keys
$_SESSION['ROOT_DIR'] = "http://".$_SERVER['HTTP_HOST']."/ppa/";
$_SESSION['ROOT_PATH'] = $_SERVER['DOCUMENT_ROOT']."/ppa/";
include "includes/db_connect.php";
include "includes/functions.php";
include "includes/required.php";
//See if there are any sales that need printing
if ($stmt = $mysqli->prepare("SELECT quantity FROM sales WHERE printed = 0 AND DATE_FORMAT(saledatetime, '%Y/%m/%d') = ? AND venue = ?")) {
$stmt->bind_param('ss',$_SESSION['session_date'],str_replace(" ","",strtolower($_SESSION['venue'])));
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($qty);
$new = 0;
while($stmt->fetch()) {
$new = ($new + $qty);
}
//Close connection
$stmt->free_result();
$stmt->close();
}
//See if an upload has been done
if ($stmt = $mysqli->prepare("SELECT id FROM images WHERE udate = ? AND venue = ?")) {
$stmt->bind_param('ss',$_SESSION['session_date'],str_replace(" ","",strtolower($_SESSION['venue'])));
$stmt->execute();
$stmt->bind_result($imgs_tmp);
$rows = $stmt->num_rows;
$stmt->free_result();
$stmt->close();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
你試過在'$ stmt-> close();'之前運行'$ stmt-> free_result();' – Diamondo25
是的,如果我這樣做的第二個查詢以及錯誤不顯示,但我沒有返回行時應該是:S –
這是整個腳本?第二個查詢沒有'$ stmt-> close();'但應該有。 –