FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Accessing different resultsets that were created by a mysql stored procedure
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Accessing different resultsets that were created by a mysql stored procedure [message #169643] Tue, 21 September 2010 12:06 Go to previous message
Jan Mielke is currently offline  Jan Mielke
Messages: 2
Registered: September 2010
Karma:
Junior Member
Hi everone,
I am just learning how to connect to a mysql server using php. I am
familiar to use mysql with stored procedures and java as frontend and I
want to use the same procedures (the same database) in php, but I can
not find a solution for the following problem.


Mainly all of my stored procedures return three resultsets (RS).

1.) RS1: contains an error-code
2.) RS2: contains an error-message
3.) RS3: contains the result I am interested in

In java it is possible to first take a look at the RS1 and then either
on RS2 or RS3 depending on the code in RS1 (procedure produced errors
or not...)


Here is an example for the idea of such a stored procedure:

MYSQL:
======

DROP PROCEDURE IF EXISTS `uspBeispiel` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `uspBeispiel`()
BEGIN

DECLARE rResultMsg varchar(255);
DECLARE rResultInt int;

SET rResultMsg = 'OK';
SET rResultInt = 1;

-- Executing some code. If the code produces errors[1] I store
-- an errormessage and an error code in rResultMsg and rResultInt.

-- [1] (Imagine you are working on a a treestructure and you want to
-- ensure that all children that are added by your procedure
-- have unique names regarding to the parentnode)

IF(rResultInt = 1) THEN

-- IF needed I return the information I am interested in.
-- (for example the complete treestructure. Here very simple:)

SELECT "Beispiel" AS Test;

END IF;

SELECT rResultMsg AS ResultMsg;
SELECT rResultInt AS ResultInt;

END $$


PHP:
====

My class connects to the database using the following lines in the
constructor:

$this->connection = mysql_connect(MYSQL_SERVER,
MYSQL_SERVER_USER,
MYSQL_SERVER_USER_PWD,
true,
65536);

if(!$this->connection) {
throw new Exception(mysql_error());
}

$this->db = mysql_select_db(MYSQL_DATABASE, $this->connection);

if(!$this->db) {
throw new Exception(mysql_error());
}


and here is the code that I use to call the procedure:


function beispiel() {

$sql = "CALL uspBeispiel()";
$result = mysql_query($sql) or die(mysql_error());

// And at this point I have the problem, that i only can access
// the first resultset, that was created by my procedure.
//
// That would be:
// SELECT "Beispiel" AS Test
// if no error occured (I have not changed rResultInt in
// uspBeispiel())

}


I hope I described my problem in an understandable way. English is not
my native language.

Best regards,
Jan
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ...
Next Topic: Re: Php Include bug in firefox
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 05:22:33 GMT 2024

Total time taken to generate the page: 0.05131 seconds