p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > PHP/MySQL > PHP Databases
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 18th, 2008, 09:48 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Empty result set from mysql stored procedure

I'm trying to use mysql stored procedures to define my graphs in my new php app, but it's not quite working as I expect. One of my stored procedures is:

Code:
DELIMITER $$

DROP PROCEDURE IF EXISTS `flightmon`.`sp_graphAvgLowest`$$
CREATE DEFINER=`flightmonadmin`@`IP` PROCEDURE `sp_graphAvgLowest`()
BEGIN

select    'textlin' as 'graphType',
    'Average of lowest prices found each day from\n%s to %s' as 'graphTitle',
    'depart_date' as 'xCol',
    'price' as 'yCol',
    'TRUE' as 'bCentAvg',
    'TRUE' as 'bOverallAvg';

select    depart_date,
    avg(price) as price,
    query_date 
from (    select    depart_date,
        min(price) as price,
        query_date 
    from flightInfo 
    group by depart_date, 
        query_date 
    order by depart_date) as selection 
group by depart_date order by depart_date asc;

END$$

DELIMITER ;
So, as you can see, I'm trying to just use a select statement to retrieve pre-set data to set up my graph inputs, and then have a second result set that contains the actual graph data. I was trying to do it this way so that I don't have to do any code changes to add available graphs to the project.

But, when I call it in my php code, the first result set that should have all my graph config data isn't there:
Code:
// Open db connection:
$con = new mysqli("<db_addr>","<username>","<password>", "<database>");
if (!$con)
{
    die('Could not connect: ' . mysqli_error());
}

// Get graph selection code from GET:
$graphProcName = getGraphProcName($con, $_GET);

if ($con->query("call ".$graphProcName))
    echo "Call successful...<br>";
else
    echo "Problems during call... Error Code: ".$con->errno." Error Message: ".$con->error."<br>";
$graphDetails = null;
$result = null;

if ($graphDetailsResult = $con->store_result())
{
    echo "Rows in first result: ".$graphDetailsResult->num_rows."<br>";
    if ($graphDetails = mysqli_fetch_assoc($graphDetailsResult))
        echo "got rows!";
    $graphDetailsResult->close();
}

echo "<br>graphType: ".$graphDetails['graphType'];
echo "<br>graphTitle: ".$graphDetails['graphTitle'];
echo "<br>xCol: ".$graphDetails['xCol'];
echo "<br>yCol: ".$graphDetails['yCol'];
echo "<br>bCentAvg: ".$graphDetails['bCentAvg'];
echo "<br>bOverallAvg: ".$graphDetails['bOverallAvg'];
The call completes successfully (no db errors show up when I check that the call completed), but the first result set has no rows in it.

When I go to the next result set, I can loop through the data, and it's all there (I can display all of the entries for depart_date and price), just the first select of static text doesn't seem to be pulling anything back.

As an aside, this stored procedure pulls back two result sets with exactly what I am expecting when I run it in msyql query browser.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old December 19th, 2008, 10:33 PM
Friend of Wrox
Points: 4,805, Level: 29
Points: 4,805, Level: 29 Points: 4,805, Level: 29 Points: 4,805, Level: 29
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
Default

I'm sure I already know the answer, but...

What happens if you change the SP to only return the first result set? Does it THEN come back okay??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old December 23rd, 2008, 11:21 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had a whole response typed up but my browser crashed... (repeatable crash for me, ctrl+z in firefox on ubuntu 8.10 causes crash for me)

I changed my SP to just return the first result set, and it retrieved nothing:
Code:
procString: call sp_graphAvgLowest
Call successful...
No result set returned!

graphType: 
graphTitle: 
xCol: 
yCol: 
bCentAvg: 
bOverallAvg:
The call completed successfully, but no result was returned.

Here is the updated SP with only the first result set:
Code:
DELIMITER $$

DROP PROCEDURE IF EXISTS `flightmon`.`sp_graphAvgLowest`$$
CREATE DEFINER=`<name goes here>` PROCEDURE `sp_graphAvgLowest`()
BEGIN

select    'textlin' as 'graphType',
    'Average of lowest prices found each day from\n%s to %s' as 'graphTitle',
    'depart_date' as 'xCol',
    'price' as 'yCol',
    'TRUE' as 'bCentAvg',
    'TRUE' as 'bOverallAvg';

/*select    depart_date,
    avg(price) as price,
    query_date 
from (    select    depart_date,
        min(price) as price,
        query_date 
    from flightInfo 
    group by depart_date, 
        query_date 
    order by depart_date) as selection 
group by depart_date order by depart_date asc;*/

END$$

DELIMITER ;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old December 28th, 2008, 05:58 PM
Friend of Wrox
Points: 4,805, Level: 29
Points: 4,805, Level: 29 Points: 4,805, Level: 29 Points: 4,805, Level: 29
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
Default

Sorry...missed this post of yours.

I dunno what to tell you. I tried this (the single SELECT, not the two of them) with ASP (instead of PHP) and it worked fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty DataSet Populated By Stored Procedure WestAussie Visual Studio 2005 5 April 8th, 2008 03:42 PM
Illegal operation on empty result set. amisrivas JSP Basics 2 February 19th, 2008 11:49 PM
stored procedure with two result sets joxa83 SQL Server 2000 14 July 18th, 2007 02:03 AM
How to set Oracle Stored Procedure Timeout jcslam Oracle 0 October 18th, 2004 04:38 AM
getting a specific row from a MySQL result set Tachyon Beginning PHP 3 July 12th, 2004 12:55 PM



All times are GMT -4. The time now is 09:46 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc