473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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 2 '10 #1
2 9768
JamieHowarth0
533 Expert 512MB
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 2 '10 #2
JamieHowarth0
533 Expert 512MB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Abdulla Herzallah | last post by:
Hi every one I have tried to search for any links, hints clues on how to create a Stored Procedure programmatically using C# but came back with empty handed :-( I know it is definitly possible...
1
by: yuliad | last post by:
How can I call stored procedure with optional parameters? Is it ODBC support naming notation for stored procedure parameters? I try to execute the following statement from the C++ program and catch...
3
by: Joseph Lu | last post by:
Hi, all I have a stored procedure created in SQL Server like the following lines. // stored proceudre code starts here CREATE PROCEDURE sp_insertdata @strdata varchar(250) , @rsult BIT...
3
by: sarma | last post by:
Hi friends, I created a stored procedure in MySQL like create procedure p() select NOW(); I write a C program, from which i wish to call this stored procedure, i used both...
1
by: sowmyavenkat | last post by:
hi all, Iam working on a Maintainance and enhancement project. It was developed by somebody. Now there is a bug which is to be solved. Can any body help me to find out which stored procedure is...
3
by: Mario Protto | last post by:
hi all, PHP 4.3.10 and MySQL 5.0, trying ____________________________________ $link = mysql_connect(DB_HOST.":".DB_PORT, DB_USER, DB_PW) or die("Could not connect:" . mysql_error());...
2
by: E11esar | last post by:
Hello there. I am going in bit of a circle with this matter; First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line...
3
akashazad
by: akashazad | last post by:
Hi Friends My question is "can we call Stored Procedure from a User Defined Function in SQL" If yes then pl tell me how? If No then pl tell me why not ? While I was trying finding...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.