364,111 Members | 2127 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

How can I get OUT parameters from a call to a stored procedure in MySQL using php?

clintolin
P: 1
My environment
php 5.3.0
MySQL Server version: 5.1.37
MySQL client version: 5.1.37
xampp for windows 1.7.2
Windows 7

The Error message I get is this:
Array ( [0] => HY000 [1] => 1414 [2] => OUT or INOUT argument 3 for routine cmcs.spLogin is not a variable or NEW pseudo-variable in BEFORE trigger )

The php code looks like this:
Expand|Select|Wrap|Line Numbers
  1. $pdo=new PDO("mysql:host=localhost;dbname=mydb;","dbuser","secret");
  2. //$query=$pdo->prepare("call spLogin(:USERNAME,:PASSWORD, @ROLLTYPEID, @RollType, @LastLogin, @LoginCount, @CreateDate, @UpdateDate, @isActive )");
  3. //$query=$pdo->prepare("call spLogin(?,?, ?, @RollType, @LastLogin, @LoginCount, @CreateDate, @UpdateDate, @isActive )");
  4. $query=$pdo->prepare("call spLogin(?,?,?,?,?,?,?,?,?)");
  5. //$query->bindParam(':USERNAME',$this->UserName);
  6. //$query->bindParam(':PASSWORD',$this->Password);
  7. //$query->bindParam(':ROLLTYPEID',$value, PDO::PARAM_INT); 
  8. $query->bindParam(1,$this->UserName);
  9. $query->bindParam(2,$this->Password);
  10. $query->bindParam(3,$value, PDO::PARAM_INT); 
  11. //$query->bindParam(3,$value, PDO::PARAM_INT, 11); 
  12. $query->bindParam(4,$this->RollType, PDO::PARAM_STR, 50);
  13. $query->bindParam(5,$this->LastLogin, PDO::PARAM_STR, 50);
  14. $query->bindParam(6,$this->LoginCount, PDO::PARAM_INT);
  15. $query->bindParam(7,$this->CreateDate, PDO::PARAM_STR, 50);
  16. $query->bindParam(8,$this->UpdateDate, PDO::PARAM_STR, 50);
  17. $query->bindParam(9,$this->IsActive, PDO::PARAM_INT);
  18.  
  19. $result = $query->execute();
  20. if(!$result) {
  21.   $errArray=$query->errorInfo();
  22.   print_r($errArray);
  23. } else {        
  24.   $this->Status = "Testing: ".$this-RollType;
  25. }
The stored procedure looks like this:
Expand|Select|Wrap|Line Numbers
  1. DELIMITER $$
  2.  
  3. DROP PROCEDURE IF EXISTS `spLogin` $$
  4. CREATE DEFINER=`root`@`localhost` PROCEDURE `spLogin`(  IN _UserName VARCHAR(50),
  5.                       IN _Password VARCHAR(50),
  6.                       OUT _rollTypeId INT,
  7.                       INOUT _rollType VARCHAR(50),
  8.                       INOUT _lastLogin DATETIME,
  9.                       INOUT _loginCount INT,
  10.                       INOUT _createDate DATETIME,
  11.                       INOUT _updateDate DATETIME,
  12.                       INOUT _isActive BOOL )
  13. BEGIN
  14.   DECLARE _userId int;
  15.  
  16.   SELECT  UserId,
  17.           `User`.RollTypeId,
  18.           `RollType`.RollType,
  19.           LastLogin,
  20.           LoginCount,
  21.           CreateDate,
  22.           UpdateDate,
  23.           IsActive
  24.     FROM  `User` JOIN `RollType` ON User.RollTypeId = RollType.RollTypeId
  25.    WHERE  UserName = _UserName
  26.      AND  `Password` = SHA1(_Password)
  27.     INTO  _userId,
  28.           _rollTypeId,
  29.           _rollType,
  30.           _lastLogin,
  31.           _loginCount,
  32.           _createDate,
  33.           _updateDate,
  34.           _isActive;
  35.  
  36.   IF _isActive = TRUE THEN
  37.     SET _loginCount = _loginCount + 1;
  38.     SET _lastLogin = NOW();
  39.   END IF;
  40.  
  41.   UPDATE `user`
  42.      SET LoginCount = _loginCount,
  43.          LastLogin = _lastLogin
  44.    WHERE UserID = _userId
  45.      AND IsActive = TRUE;
  46.  
  47. END $$
  48.  
  49. DELIMITER ;
Thanks for your help!
clint
Jan 1 '10 #1
Share this Question
Share on Google+
2 Replies


codegecko
Expert 100+
P: 363
Hi Clint,

This post on the MySQL forums shows how to use inline parameters to execute a store procedure and return the results in the format:
Expand|Select|Wrap|Line Numbers
  1. CALL myproc (@param1, @param2); SELECT @param1, @param2;
  2.  
This should then return a one-row resultset with the parameters successfully modified by your stored procedure.
If this doesn't work let us know and we'll try and find another solution.

Hope it helps,

codegecko
Jan 1 '10 #2

codegecko
Expert 100+
P: 363
Hi Clint,

Did this work for you? If so, if you could mark the individual post with "choose as best answer" (or I can do it for you) that'd be great, it helps other people to find the solution quicker for the given problem. If not, let us know and we'll try and find another solution.

Thanks,

codegecko
Jan 9 '10 #3

Post your reply

Help answer this question



Didn't find the answer to your PHP question?

You can also browse similar questions: PHP array ( [0]