473,836 Members | 1,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP and MySQL: How to Properly call a Stored Procedure with Output Parameters from PHP - mysql, mysqli, or PDO

Hi All,

I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am
unable to call a MySQL stored procedure that returns output parameters
using mysql, mysqli, or PDO. I'm having a hell of a time with it...

The following comes from phpinfo():
PHP Version: 5.1.2
mysql Client API version: 5.0.18
mysqli Client API version: 5.0.18
PDO Driver for MySQL, client library version: 5.0.18

MySQL version, from running SELECT version(); = 5.0.18

Here's the procedure I've created in MySQL:
CREATE PROCEDURE testproc(OUT p_testvar varchar(50)) BEGIN SET
p_testvar = 'HELLO WORLD!'; END
From the MySQL Command Line, I can do the following:

mysql> call testproc(@a);
Query OK, 0 rows affected (0.00 sec)

mysql> select @a;
+--------------+
| @a |
+--------------+
| HELLO WORLD! |
+--------------+
1 row in set (0.00 sec)

Now, on the PHP side, I'm using the code samples in the documentation
at:
http://www.php.net/manual/en/ref.pdo.php

under the heading "Example 9. Calling a stored procedure with an output
parameter"

<?
$user = "username";
$pass = "pAsSwOrD";

try {
$dbh = new PDO('mysql:host =localhost;dbna me=myDB', $user, $pass);

$stmt = $dbh->prepare("CAL L testproc(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);

// call the stored procedure
$stmt->execute();

print "procedure returned $return_value\n ";

$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
When I run this PHP file, it outputs nothing. No output whatsoever.
No error, no source code, nothing. Database username and password are
the same as those I'm using when I log in at the mysql command line.

I've tried using named parameters as well, with no success.
Just FYI, I can run the following from PHP:
<?
$user = "username";
$pass = "pAsSwOrD";

try {
$dbh = new PDO('mysql:host =localhost;dbna me=myDB', $user, $pass);

foreach ($dbh->query('SELEC T * from url_redirect') as $row) {
print_r($row);
}

$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>

and I get the rows from the table.

I've also tried using the mysqli extension, rather than PDO. I'm using
the examples at
http://mysql.gilfster.com/page.php?p...&page_id=4.0.3 - using
the code sample under the section titled "Using Parameters", right
above the link to "php_proc_hello world.phx". My code is as follows:

<?php
$user = "username";
$pass = "pAsSwOrD";
$db = "databasena me";

$link = mysqli_connect( "localhost",$us er,$pass);

if (mysqli_connect _errno()) {
echo "connection error";
exit();
}

mysqli_select_d b ($link,$db);

if ($result = mysqli_multi_qu ery($link,"call testproc(@out_p aram)")) {

if ($result = mysqli_multi_qu ery($link,"sele ct @out_param")) {

$row = mysqli_fetch_ar ray($result, MYSQLI_NUM);

printf($row[0]);

mysqli_free_res ult($result);

} else { echo "problem :( inner "; }

} else { echo "problem :( outer"; }

?>
When I run this, I also get nothing. No errors, no output, nothing.
The browser completes the load of the page, but it has no output on it.
Any thoughts or advice is greatly appreciated. I'm willing to try
almost anything at this point - I'm totally stumped.

Thanks,

Evan

Apr 10 '06 #1
0 19302

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6708
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
1
2779
by: James | last post by:
Hey everyone, I have a really obscure but impassable problem with a reasonably simple piece of php/PEAR DB/MySQL code When calling several stored procs the first call succeeds, but subsequent calls fail no matter which SP is called first it always works, and the rest fail... with: >>>
3
7975
by: Chris | last post by:
Hello everyone I want to call a DB2 7.2 stored procedure via ADO in VC++ 7.1 It has 4 parameters, the 1st and the 4th are OUTPUT and the others are INPUT params. My code looks like this: (spCMD is a Command, spCON a Connection, spRS a Resultset, and spPARAM are Parameters) spCMD->Name = "mySPname";
2
2517
by: James | last post by:
Hey everyone... I'm having an issue with a seemingly simple piece of PHP/MySQL I have a stored procedure in MySQL5 as such: SQL: -------------- DELIMITER $$; DROP PROCEDURE IF EXISTS `test`.`sp_returns_string`$$ CREATE PROCEDURE `test`.`sp_returns_string`(OUT vOutput varchar(32))
4
4998
by: Pakna | last post by:
Hi, is there any way to call a JAVA stored procedure from a SQL Trigger? We are having difficulties with this and cannot verify whether DB2 even *has* this capability? Thank you very much....
1
3821
by: eholz1 | last post by:
Hello PHP Group, Is there any advantages (or disadvantages) in using mysqli instead of mysql (querys, connections to database, etc). I am currently using mysql_connect, and things like this: $result = @mysql_query("SELECT * FROM images3 WHERE id=" . $img . " AND p=" .$p. ""); to access my database. I see that some people are using the
1
3092
by: Frank Moyles | last post by:
I have two simple function in PHP that I want to convert to C# - function Doit($enc_user_name, $enc_password) { $result = $mysqli->query("call sp_userAuth('$enc_user_name','$enc_password')"); if (mysqli_num_rows($result) != 0) { $data = $result->fetch_array(MYSQLI_BOTH);
1
14058
by: preejith | last post by:
Error Code : 1329, No data - zero rows fetched, selected, or processed. MYSQL I am getting the following error while running a stored procedure in mysql5.0 Error Code : 1329 No data - zero rows fetched, selected, or processed. I have an stored procedure SP1 which calls stored procedure SP2 and SP2 calls a function F1. I have run this script from .bat file.
1
9598
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
9816
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.