gpt4 book ai didi

php - 存储过程返回空结果

转载 作者:可可西里 更新时间:2023-11-01 08:05:35 27 4
gpt4 key购买 nike

下面是我的存储过程:

DELIMITER $$
--
-- Procedures
--
DROP PROCEDURE IF EXISTS `checkLogin`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `checkLogin`(IN `uname` VARCHAR(255), IN `pwd` VARCHAR(255))
BEGIN
SELECT a.id, a.role_id, b.name FROM userTable as a
LEFT JOIN roleTable as b on b.id = a.role_id
WHERE a.username = uname AND password = pwd;
END$$

DELIMITER ;

下面是我的执行代码:

    $stmt = $this->dbCon->prepare("CALL checkLogin(?, ?)");

$stmt->bindParam(1, $email, PDO::PARAM_STR, 4000);
$stmt->bindParam(2, $password, PDO::PARAM_STR, 4000);

// call the stored procedure
$stmt->execute();

//var_dump($res);
$op = ( $stmt ) ? $stmt->fetchAll(PDO::FETCH_ASSOC) : '';

echo '<pre>'; print_r($op); die;

上面的$this->dbCon是我的PDO对象。

当我执行这段代码时,我只得到空结果。但是当我通过 phpmyadmin 运行程序时,它工作正常。

即使我通过命令行执行它也能正常工作:

enter image description here

我也尝试了下面的方法(从回答中收到),但仍然不成功

$stmt = $db->prepare("Call checkLogin(?,?);");
$stmt->execute(array($email,$password));

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

if (count($rows) == 0)
echo 'Failed Login!'."\n";
else
echo 'Logged In...'."\n".print_r($rows,true);

最佳答案

你可以尝试某些方法,这是另一种在执行方法中直接传递键值参数的方法,命名占位符应该在过程中传递

$stmt = $this->dbCon->prepare("CALL checkLogin(:Email, :Password)");

$keyArray = array("邮箱"=>"test@test.com","密码"=>"123456");

$stmt->执行($keyArray);

关于php - 存储过程返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29346859/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com