If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Output Parameter Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-11, 02:09
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
Output Parameter Problem

Hi,
I am calling Stored Procedure from PHP and i am running out with errors. So i changed OUT to IN Parameter and SET _Status to SELECT 'Role Already Exists' but am not getting those results
Here is my code,
Code:
DELIMITER $$
CREATE PROCEDURE SP_Register_Role(
    IN _Role_Name VARCHAR(10),
    OUT _Status VARCHAR(30))
 BEGIN
    DECLARE CheckExists int;
    SET CheckExists = 0;
    SELECT COUNT(*) INTO CheckExists FROM Role_Master WHERE Role_Name = _Role_Name;
    IF CheckExists > 0 THEN
        SET _Status = 'Role Already Exists';
    ELSE
        INSERT INTO Role_Master(Role_Name) VALUES(_Role_Name);
        SET _Status =  'Role Created';
    END IF;
END$$
Code:
$dbh = PHP_DB_Connect();
		$Qry = $dbh->prepare("CALL SP_Register_Role(?,?)");
		$Qry->bindParam(1,$_POST["RoleName"],PDO::PARAM_STR,10);
		$Qry->bindParam(2,$SP_Return_Value,PDO::PARAM_STR|PDO::PARAM_INT_OUT,30);
		$Result = $Qry->execute();
		if(!$Result){
			  $arr = $Qry->errorInfo();
			  print_r($arr);
		}else{
			print $SP_Return_Value;
		}
Reply With Quote
  #2 (permalink)  
Old 04-17-11, 08:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
why are you even bothering to use a stored procedure here?

there are two options to the INSERT statement that you could be using -- IGNORE, or, alternatively, ON DUPLICATE KEY UPDATE
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-17-11, 09:30
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
Hi thankyou,
Are you telling not to use stored procedure here? do i need to handle this with query alone ?
any examples ?
Reply With Quote
  #4 (permalink)  
Old 04-17-11, 09:40
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
Hi thankyou,
Are you telling not to use stored procedure here? do i need to handle this with query alone ?
any examples ?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On