我是编写MySQL存储过程的新手,我遇到了一些问题。
这是存储过程:
DELIMITER $$
DROP PROCEDURE IF EXISTS login$$
CREATE PROCEDURE login(
IN usern VARCHAR(11),
IN pw VARCHAR(30),
OUT msg VARCHAR(50)
)
login_proc:
BEGIN
SELECT COUNT(*) as voter
FROM regVoter
WHERE studentID = usern AND password = pw;
IF voter = 1 THEN
SET msg = "login successfully";
ELSE
SET msg = "login failed";
END IF;
LEAVE login_proc;
END $$
DELIMITER ;
以下是要在其中调用存储过程的PHP文件:
<?php
ini_set('display_errors','1'); error_reporting(E_ALL);
include_once 'dbConnect.php';
$username = $_POST['username'];
$password = $_POST['password'];
if (connect()){
global $conn;
$query = $conn->query("CALL login('$username','$password',@msg)") or die("Query failed: " . $conn->error);
$result = $conn->query("SELECT @msg AS data");
$row = $result->fetch_assoc();
echo $row['data'];
}
else{
$data = "connection error!";
}
?>
我得到的错误是&#34;未捕获错误:在布尔值&#34;上调用成员函数fetch_assoc()这意味着其中一个查询返回false。
我在这里做错了什么?
答案 0 :(得分:0)