我无法弄清楚为什么这不起作用。如果删除它,数据库会在die staitment工作后正确连接所有内容。我得到所有4的计数值'',但如果我手动执行命令
SELECT count(*) FROM `models` WHERE `fair` LIKE '%,C,%'
我得到260
作为结果。
这是我的代码。
<?php
require_once "includes/config.php";
// Create connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATA);
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
//get list of fair options
$fairOptions=array(
"C"=>"Center of gravity centered",
"F"=>"Faces all same size",
"T"=>"Same relationship with all other faces",
"L"=>"Same friction on all faces"
);
$query="SELECT count(*) FROM `models` WHERE `fair` LIKE ?";
$stmt = $conn->stmt_init();
$stmt->prepare($query);
$stmt->bind_param('s',$test);
$stmt->bind_result($count);
foreach ($fairOptions as $key=>&$value) {
$test="%,?,%";
$stmt->execute();
echo $key . "=>" . $count . "<Br>";
$value="$value($count)";
}
die();