Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stored procedure returns empty result

Below is my stored procedure:

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 ;

Below is my execution code:

    $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;

in the above $this->dbCon is my PDO object.

When I execute this code I am getting only empty result. But when I run the procedure through phpmyadmin it is working fine.

Even it is working fine if I execute through command line:

enter image description here

I tried below method also (Received from Answer), But still its unsuccessful

$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);
like image 203
Butterfly Avatar asked May 20 '26 09:05

Butterfly


1 Answers

you can try certain method, this is another way to pass the key value parameter in execute method directly and naming placeholder should be passed in procedure

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

$keyArray = array("Email"=>"[email protected]","Password"=>"123456");

$stmt->execute($keyArray);

like image 121
sandeep_kosta Avatar answered May 22 '26 23:05

sandeep_kosta