我使用mysqli编写了一个PHP函数,我得到的结果与MySQL数据库中存储的结果不同。我在phpMyAdmin中尝试了MySQL命令,一切都按照我的预期回来了。
Users Table
---------------------------------------------------------------------
Id [int(11)]|Username [varchar(16)]|Status [enum('Active', 'Inactive')]
---------------------------------------------------------------------
1 | ABC | Active
2 | DEF | Active
PMK Table
------------------------------
Id [int(11)]|Camel [tinyint(1)]
------------------------------
1 | 1
2 | 0
function getFeature($script, $username, $feature)
{
global $mysqli;
$stmt = $mysqli->prepare("SELECT Id FROM Users WHERE Username = ? AND Status = 'Active'");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($id);
$id = $stmt->fetch();
$stmt->free_result();
if(isset($id) && !empty($id))
{
switch($script)
{
case "PMK":
switch($feature)
{
case "Camel":
$stmt = $mysqli->prepare("Select Camel FROM PMK WHERE Id = $id");
$stmt->execute();
$stmt->bind_result($access);
$access = $stmt->fetch();
$stmt->free_result();
printf("%s:%s:%s:%s", $script, $feature, $username, $access);
break;
default:
echo "[ERROR]";
break;
}
break;
default:
echo "[ERROR]";
break;
}
} else {
echo "[ERROR]";
}
$stmt->close();
}
我的功能是否出错会导致我的结果不同?
答案 0 :(得分:0)
很高兴你们这么有帮助:D