【发布时间】:2018-04-13 18:55:49
【问题描述】:
当我使用 php mysqli 在表中显示结果(使用数据表)时,此代码工作正常
$result = mysqli_query($con, $query);
if (!$result) {
die("Database query failed.");
}
$res = array();
while ($row = $result->fetch_array()) {
array_push($res, $row);
}
echo json_encode($res);
{
data: "distributor_name"
}, {
data: "order_date"
}, {
data: "product_name"
}, {
data: "nsp"
}, {
data: "region"
}, {
data: "current-sales"
}, {
data: "closing-balance"
}, {
data: "CBTotal"
},{
data: "CSTotal"
},{
data: "pro_ID"
}
但是我想使用php准备好的语句,这段代码有什么错误?如何在那里传递php变量?
$stmt->bind_result($distributor_name, $order_date, $product_name, $nsp, $region, $pro_ID, $current_sales, $closing_balance);
$json = array();
while($row = $stmt->fetch()){
array_push($json, $row);
}
echo json_encode($json);
$stmt -> close();
【问题讨论】:
-
为什么一定要使用prepared statement?
标签: php json mysqli datatables prepared-statement