MySQL Forums :: PHP :: Query return from a Stored Procedure

Advanced Search

Query return from a Stored Procedure
Posted by: Mike Barlow ()
Date: September 26, 2012 01:41PM

I've been using MySQL on my dev environment for sometime now, but I'm just getting into using mySql Stored Procedures with PHP and PDO and have come across what is probably a newbe issue, but I can't seem to find a solution.

I've got a simple database single table (SQL statements reduced from my actual system for simplicity):

CREATE TABLE `patients` (
`patName` varchar(50) NOT NULL

This table has a single record in it:
patName = "My First Name"

I've created a simple Stored Procedure as a starting point in my efforts:
CREATE DEFINER=`root`@`localhost` PROCEDURE `get_patients`()
SELECT patName from patients;

And I have a simple PHP script to call that stored proc via PDO:
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
foreach($DBH->query( 'CALL get_patients()' ) as $row) {

echo "<br><br>JSON Dump<br>";
echo json_encode($row, JSON_FORCE_OBJECT);

The output from this PHP code is:
'patName' => string 'My First Name' (length=19)
0 => string 'My First Name' (length=19)

{"patName":"My First Name","0":"My First Name"}

Ok now here's my question/problem.

Notice that in both the var_dump and the JSON Dump there are 2 elements being returned ("patName" and "0") both of which have the same value.

How do I get only the one element ({"patName":"My First Name"}) to be returned???

Am I doing something wrong (or more likely missing something) in my stored proc or in my PDO processing?

I know I could probably kludge something up in PHP but I'm hoping that I'm missing something simple and obvious as a soltion.

Signed "Puzzled, Puzzled"

Options: ReplyQuote

Subject Written By Posted
Query return from a Stored Procedure Mike Barlow 09/26/2012 01:41PM
Re: Query return from a Stored Procedure - SOLVED Mike Barlow 09/27/2012 11:05AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.