473,508 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 9779
JamieHowarth0
533 Recognized Expert Contributor
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 Recognized Expert Contributor
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
6678
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
9023
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
1524
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
8202
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
7206
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
1793
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
2760
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
2983
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
7654
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
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
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
7401
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...
1
7063
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
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.