473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BIG PDO issues with StoredProc output params with PHP 5 and MySQL5

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_retu rns_string`$$
CREATE PROCEDURE `test`.`sp_retu rns_string`(OUT vOutput varchar(32))
BEGIN
SET vOutput = 'It Worked';
END$$
DELIMITER ;$$
--------------

And a piece of PHP that uses PDO to call the Stored Proc as such:

PHP:
--------------
<?php

//First - check/load PDO!
if (!extension_loa ded('pdo_mysql' )) {
// If not loaded we could try loading it manually
$prefix = (PHP_SHLIB_SUFF IX == 'dll') ? 'php_' : '';
if (!@dl($prefix . 'pdo_mysql.' . PHP_SHLIB_SUFFI X)) {
die('pdo_mysql unavailable');
}
}

$DB_host = "localhost" ; // the hostname of the database server
$DB_user = "root"; // YOUR username to connect with
$DB_pass = "password"; // YOUR user's password
$DB_dbName = "test"; // the name of the database to connect to
$DB_dbType = "mysqli"; // the type of database server.

$DB_Con = "mysql:host=$DB _host;dbname=$D B_dbName";
$dbOptions = array();

//Create a DB connection
$db = new PDO($DB_Con, $DB_user, $DB_pass, $dbOptions);

$return_value = '';
$stmt = $db->prepare("CAL L sp_returns_stri ng(@?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
$stmt->execute();
print_r($stmt);
print "<br/>Returned: $return_value<b r/><br/>\r\n";
?>
--------------

This should print something like this:
--------------
PDOStatement Object ( [queryString] => CALL sp_returns_stri ng(@?) )
Returned: It Worked!
--------------

But unfortunately it NEVER returns anything.
The Stored Proc works fine and returns the string ok, but only when I'm
calling it from an SQL console.

The PHP PDO documentation says to use:
--------------
$return_value = '';
$stmt = $db->prepare("CAL L sp_returns_stri ng(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
--------------
Note the missing "@".
But when I do this, it complains that the parameter isn't a variable and
the call dies.

(see: http://www.php.net/pdo/ for the examples)

Any help would be great!

Thanks.
James.
Jan 10 '06 #1
2 2504
I have always used named parameters with PDO. I don't like having to rely on
the parameter order.

$stmt = $db->prepare( "SELECT foo FROM bar WHERE baz = :baz" );
$stmt->bindParam( ':baz', 123 );
$stmt->execute();

Did you try using PDO with a simple query first using your @? symbol? The
problem might not be with the stored procedure, but with the parameter
binding.

--
Louis-Philippe Huberdeau

James wrote:
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_retu rns_string`$$
CREATE PROCEDURE `test`.`sp_retu rns_string`(OUT vOutput varchar(32))
BEGIN
SET vOutput = 'It Worked';
END$$
DELIMITER ;$$
--------------

And a piece of PHP that uses PDO to call the Stored Proc as such:

PHP:
--------------
<?php

//First - check/load PDO!
if (!extension_loa ded('pdo_mysql' )) {
// If not loaded we could try loading it manually
$prefix = (PHP_SHLIB_SUFF IX == 'dll') ? 'php_' : '';
if (!@dl($prefix . 'pdo_mysql.' . PHP_SHLIB_SUFFI X)) {
die('pdo_mysql unavailable');
}
}

$DB_host = "localhost" ; // the hostname of the database server
$DB_user = "root"; // YOUR username to connect with
$DB_pass = "password"; // YOUR user's password
$DB_dbName = "test"; // the name of the database to connect to
$DB_dbType = "mysqli"; // the type of database server.

$DB_Con = "mysql:host=$DB _host;dbname=$D B_dbName";
$dbOptions = array();

//Create a DB connection
$db = new PDO($DB_Con, $DB_user, $DB_pass, $dbOptions);

$return_value = '';
$stmt = $db->prepare("CAL L sp_returns_stri ng(@?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
$stmt->execute();
print_r($stmt);
print "<br/>Returned: $return_value<b r/><br/>\r\n";
?>
--------------

This should print something like this:
--------------
PDOStatement Object ( [queryString] => CALL sp_returns_stri ng(@?) )
Returned: It Worked!
--------------

But unfortunately it NEVER returns anything.
The Stored Proc works fine and returns the string ok, but only when I'm
calling it from an SQL console.

The PHP PDO documentation says to use:
--------------
$return_value = '';
$stmt = $db->prepare("CAL L sp_returns_stri ng(?)");
$stmt->bindParam(1, $return_value, PDO::PARAM_STR, 4000);
--------------
Note the missing "@".
But when I do this, it complains that the parameter isn't a variable and
the call dies.

(see: http://www.php.net/pdo/ for the examples)

Any help would be great!

Thanks.
James.


Jan 10 '06 #2
Hey,
Thanks for the feedback.

Unfortunately using param names doesn't work either.
All Database functions seem to work perfectly "except" fro output params.
All of the examples I've found on the net point to using "?" as the
parameter rather than "@?" (or "@:name" rather than ":name" for var names)
Unfortunately when I do this, I get :
SQLSTATE: HY000
ERROR CODE: 1414
ERROR: OUT or INOUT argument 1 for routine test.sp_returns _string is not a variable

Anyway, when I include the "@" it simply returns nothing...

I just can't seem to find any working examples anywhere...

Thanks,
James.

Louis-Philippe Huberdeau wrote: I have always used named parameters with PDO. I don't like having to rely on
the parameter order.

$stmt = $db->prepare( "SELECT foo FROM bar WHERE baz = :baz" );
$stmt->bindParam( ':baz', 123 );
$stmt->execute();

Did you try using PDO with a simple query first using your @? symbol? The
problem might not be with the stored procedure, but with the parameter
binding.

--
Louis-Philippe Huberdeau

Jan 11 '06 #3

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

Similar topics

12
3591
by: Sarah Tanembaum | last post by:
Though I installed MySQL5 and PHP5, how come my phpinfo() shows as follow: MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version 3.23.57 <<<<<<<<<<<<<<< Instead of saying 3.23.57, shouldn't it show 5.xx.xx? Or, did I do something wrong?
9
1465
by: PyPK | last post by:
I was testing this piece of code and it takes about 24-30 seconds to do a look up on a list(m) of size 1000x1000 m -> list of size 1000x1000 import time print time.ctime() box = {} for r,row in enumerate(m): for c,e in enumerate(row): if box.has_key(e): params = box
2
1662
by: rob lynch | last post by:
I have been trying to get a grasp on how I can use a sqlserver storedproc as the UpdateCommand of a Dataview. The control (datview / SqlDatasource / Edit control) works great when you supply it with an adhoc sql statement (somthing that I dont' like to do for many reasons) and populating the select part with a storedproc works well also,...
1
4577
by: Khodr | last post by:
Hi everyone, I am calling an Oracle StoredProc that returns a CLOB data type value as an output parameter. What parameter data type should I use? >> I tried adLongVarChar and adVarChar with the sizes 1000, 32000, 1000000 and they all fail. Size of returned value will exceed 50k. >> I know that there is a GetChunk, but I noticed that it...
2
1497
by: andy6 | last post by:
I have the ods calling the business object. This is the method it is calling public DataTable GetEditManager(string tab, string state, int rows, int pageselected, int nbrpages, string sort, byte sortdir, int totaledits, string userid) { int a = nbrpages; int b = totaledits; if (dtProv == null)
0
2274
by: Nagapa | last post by:
Hello there, I am impressed with the questions and answers in this forums and belive this group will help me thru my issues. We are currently upgrading our application hardware. Ours is VB application(client) and that connects thru DCOMS and IBM DB2 connect 7.2 (on a win 2000 server) to backend DB2 database (7.2, due for upgrade) and...
4
3381
by: Clint Pidlubny | last post by:
Hello, I'm using ASP.Net 2.0 and the Jan 2006 Enterprise Library. What I'm doing is passing an ArrayList into a stroed procedure to do an Insert. Here's some code: Dim params as New ArrarList params.Add("first parameter value") params.Add("second parameter value")
3
1511
by: toyin | last post by:
hi, am having problem connecting to MYSQL5.1 from VS.Net.the error is database reeor:System.Data.SqlClient.SqlException:An error occur while establishnig a connection to the server. Am Using Visual Studio.Net 2003, IIS 5.0 and MySql5.1. am trying to retreve a new record from a database using a webservice. here is the sample code Imports...
4
1453
by: opswordfish | last post by:
Hi I've visited a lot of forums regarding getting MySQL5 working with PHP5 in IIS and it seems that with MYSQL5 you need to use mysqli in PHP and that you need to uncomment the extension in php.ini However I have tried both of these and I still get the error: Fatal error: Call to undefined function mysqli_connect() I was wondering if...
0
7475
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...
0
7664
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. ...
0
7918
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
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...
0
7766
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5981
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...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1897
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

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.