我刚刚开始学习预处理语句,但出于某种原因,我从我的另一个项目中复制并粘贴了这个代码(有效),它告诉我mysqli对象没有预处理语句方法。我在这段代码中忘记了什么?与问题无关的后续部分已经过编辑,但对于我尝试调用$ stmt的每个对象,它表示找不到该方法。
$dbhost = 'redacted';
$dbname = 'redacted';
$dbuser = 'redacted';
$dbpass = 'redacted';
$db = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname) or die("Error " . mysqli_error($db));
稍后会被称为:
function register($db) {
$user = $_POST['username'];
$pass = $_POST['password'];
$stmt = $db->prepare("SELECT username FROM users WHERE username=?");
$stmt->bind_param("s", $user);
$stmt->bind_result($result);
$stmt->execute();
$stmt->store_result();
$stmt->fetch();
}
switch ($action) {
case 'register':
register($db);
break;
case 'login':
login($db);
break;
}