|
|
 |
| 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.
|
 |

December 18th, 2008, 09:48 AM
|
|
Registered User
|
|
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

December 19th, 2008, 10:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,319
Thanks: 3
Thanked 69 Times in 68 Posts
|
|
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??
|

December 23rd, 2008, 11:21 AM
|
|
Registered User
|
|
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ;
|

December 28th, 2008, 05:58 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,319
Thanks: 3
Thanked 69 Times in 68 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |