Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a recordset from a MySQL 5 stored procedure in PHP 5 1

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
Hi,

I posted this in the MySQL forum but was advised to post it here since I'm dealing with PHP.

I'm trying to return a record set from my stored procedure but found out that I have to use CLIENT_MULTI_RESULTS to do it. So I put code in place that I found on several sites to call mysql_real_connect. This is my code:

Code:
$dbconnect = NULL;
$dbhost = "localhost:3307";
$dbname = "db";
$dbusername = "root";
$dbuserpass = "pass";

MYSQL mysql;
mysql_init(&mysql);
$dbconnect = mysql_real_connect(&mysql, $dbhost, $dbusername, $dbuserpass, $dbname, 3307, 0, CLIENT_MULTI_RESULTS);

The error that I'm getting is :
Code:
Parse error: parse error, unexpected T_VARIABLE in C:\The S Files\WebDev\DataQuest\includes\db.php on line 25

Line 25 is the following:
Code:
MYSQL mysql;

What am I doing wrong? I'm using PHP 5 and MySQL 5 and Smarty and am quite new at all three. Please help ... your help would be greatly appreciated ...

Regards,
VB Rookie
 
This line:

MYSQL mysql;

is not well-formed PHP code. It might have something to do with Smarty. Or not. It looks like c-language code.


Also, your code references the functions mysql_init() and mysql_real_connect(), neither of which appear in the PHP online manual.

I'm also not sure what "CLIENT_MULTI_RESULTS" is, either, or any you have to use it to connect to a stored procedure. The following:

Code:
<?php
$dbh = mysqli_connect ('localhost','test','test', 'test');

$query = "CALL get_ten(5)";

$rh = mysqli_query ($dbh, $query) or die (mysqli_error());

while ($row = mysqli_fetch_assoc ($rh))
{
	print $row['word'] . '<br>';
}
?>
works on my machine.

I'm pretty sure you're going to have to use the mysqli[/i]_* family of functions with stored procedures.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 

sleipnir214,

Yowzaa! That at least got me past the error that I was getting ... but now I'm getting no error at all and no result set. I tested my stored procedure to make sure that it actually returns data and it does ... but mysql1_error() isn't returning an errors to me ...

Do you have any ideas on this? I have display errors set to 'on' in my php.ini

- VB Rookie
 


Ok here is my code:

Code:
db_connect();
$result = mysqli_query("CALL usp_site_reference ('S', 2, 1)") or die("the errors:<br />". mysqli_error());

while ($row = mysqli_fetch_assoc ($result))
{
 print $row['reference_description_1'] . 'hi<br>';
}

Also here is my db connect code:

Code:
$dbconnect = NULL;
$dbhost = "test";
$dbname = "test";
$dbusername = "root";
$dbuserpass = "";
$dbport = "3307";

$dbconnect = mysqli_connect($dbhost, $dbusername, $dbuserpass, $dbname, $dbport);

Does anything jump out at you? I already verified that I'm connecting to the database successfully.

- VB Rookie
 

Thanks sleipnir214 ... I should've checked into that first ...
I'll see if changing that helps!

Kindest Regards,
- VB Rookie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top