Out parameter does not work with mysql.? Help me

Reply

Join Date: Jun 2009
Posts: 119
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster

Out parameter does not work with mysql.? Help me

 
0
  #1
Oct 29th, 2009
This is my Stored Procedure

DELIMITER $$
  1. DROP PROCEDURE IF EXISTS `CALL`.`sp_login`$$
  2.  
  3. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_login`(userid VARCHAR(50),pass VARCHAR(50),out chk INT(11),out user_alias VARCHAR(50),out user_tariff VARCHAR(50),out c_credit DECIMAL(15,5),out r_reseller VARCHAR(10),out r_level VARCHAR(10),out c_tariff CHAR(2))
  4. BEGIN
  5. SELECT id INTO chk FROM cc_reseller WHERE useralias =userid AND uipass=pass AND level!=0 AND activated!='0';
  6. if(chk!="") THEN
  7. SELECT id,useralias,tariff,credit,reseller,level,create_tariff INTO chk,user_alias,user_tariff,c_credit,r_reseller,r_level,c_tariff FROM cc_reseller WHERE useralias =userid AND uipass=pass AND activated!='0' AND level!=0;
  8. END if;
  9. END$$
  10.  
  11. DELIMITER ;

This is my Php Code to call StoreProcedure

  1. <?php
  2. ob_start();
  3. include_once('config.php');
  4. $username = $_POST['username'];
  5. $password = $_POST['password'];
  6.  
  7. if (isset($_POST['username']) && $_POST['username']!='')
  8. {
  9. $username=$_POST['username'];
  10. $password=$_POST['password'];
  11. $query="call sp_login('$username','$password',@chk,@user_alias,@user_tariff,@c_credit,@r_reseller,@r_level,@c_tariff)";
  12. $result=mysql_query($query) or die('Query error'.''.mysql_error());
  13. $count=mysql_fetch_row($result);
  14.  
  15.  
  16. $chk = $count[0];
  17. if($chk !="")
  18. {
  19. $n_name = $count[1];
  20. $n_tariff = $count[2];
  21. $n_username = $count[3];
  22. $n_creator = $count[4];
  23. $n_credit = $count[5];
  24. $_SESSION['username'] = $n_username;
  25. $_SESSION['user_id'] = $chk;
  26. $_SESSION['tariff'] = $n_tariff;
  27. $_SESSION['reseller'] = $n_creator;
  28. $_SESSION['ncredit'] = $n_credit;
  29.  
  30. header('Location:welcomes.php');
  31. }
  32. else
  33. {
  34. header("location:index.php?q=-2");
  35. }
  36. }
  37. else
  38. {
  39. if(!isset($_SESSION['username']) || $_SESSION['username']=='')
  40. {
  41. header("location:index.php?q=-1");
  42. }
  43. }
  44. ?>

Can anyone tell where i m wrong..
is it true that Out parameter doesnt work with mysql..???

Help me out
Last edited by sam023; Oct 29th, 2009 at 3:26 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #2
Oct 29th, 2009
No its not true, what error you get..?
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 119
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster
 
0
  #3
Oct 29th, 2009
Originally Posted by network18 View Post
No its not true, what error you get..?
  1. Query errorPROCEDURE call.sp_login can't return a result set in the given context
  2.  

Well i google little bit..!!

i got this article
http://www.artfulsoftware.com/infotree/tip.php?id=130

in it is said that Mysql Api cannot fetch out parameter..!!!

may be thats why people use mysqli..??

What do u say..?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #4
Oct 29th, 2009
i still don't understand it, did you tried it.
Check the examples given in the page here .
It might help you.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 119
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster
 
0
  #5
Oct 29th, 2009
  1. $con = mysql_connect('localhost','root','',false,65536);
can u show some light over the code..!

last two parameters makes the difference..!!

now my procedure is running..!!!
Thanks for the link
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #6
Oct 29th, 2009
great, have a nice time
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 119
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster
 
0
  #7
Oct 30th, 2009
still i dont understand the use and meaning of last two parameters..??
what is the use of it..!! earlier i never use it..?

Can u tell me that
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #8
Oct 30th, 2009
Originally Posted by sam023 View Post
still i dont understand the use and meaning of last two parameters..??
what is the use of it..!! earlier i never use it..?

Can u tell me that
sure, this last two parameters are optional,
the the but one parameter is called new_link, if its set to true, each time you call mysql_connect() new connection is created and that MYSQL link identifier is returned back.Otherwise no new link will be established, but instead, the link identifier of the already opened link will be returned.
and the last parameter called client_flags is an integer actually, has values like 'MYSQL_CLIENT_IGNORE_SPACE ', 'MYSQL_CLIENT_COMPRESS' and 'MYSQL_CLIENT_INTERACTIVE' etc.
Don't worry much about this last one, if you don't need it at the moment.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 119
Reputation: sam023 is an unknown quantity at this point 
Solved Threads: 2
sam023 sam023 is offline Offline
Junior Poster
 
0
  #9
Oct 30th, 2009
Originally Posted by network18 View Post
sure, this last two parameters are optional,
the the but one parameter is called new_link, if its set to true, each time you call mysql_connect() new connection is created and that MYSQL link identifier is returned back.Otherwise no new link will be established, but instead, the link identifier of the already opened link will be returned.
and the last parameter called client_flags is an integer actually, has values like 'MYSQL_CLIENT_IGNORE_SPACE ', 'MYSQL_CLIENT_COMPRESS' and 'MYSQL_CLIENT_INTERACTIVE' etc.
Don't worry much about this last one, if you don't need it at the moment.
Well i dont think last two parameters are optional in case of stored procedure...!! when i remove those paramemters.. Store Procedure does run at all..!! How these parameters affect the running of store procedures..?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #10
Oct 30th, 2009
yes, they seems to be important for stored procedures to execute -
When you connect and expect to use a stored procedure,you must pass a special flag to MySQL via the connect command, otherwise you will not get the results returned, and it will result in this error:
PROCEDURE AlexGrim.GetStats_ForumCategories can't return a result set in the given context

To fix this, change you connection string, adding ",false,65536" as the last 2 fields:
$this->con = mysql_connect($this->h,$this->u,$this->p,false,65536);

This is what you did.Because the constant 65536 represents the "CLIENT_MULTI_STATEMENTS", which will enable the support for using multiple statement in the query.
Why to use this, must be obvious now for you, as stored procedures are likely to have multiple statements
Last edited by network18; Oct 30th, 2009 at 5:23 am. Reason: light on using stored procedure in php
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Reply

Tags
mysql, parameter, procedure, sp, stored

Message:


Thread Tools Search this Thread



Tag cloud for mysql, parameter, procedure, sp, stored
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC