473,320 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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_returns_string`$$
CREATE PROCEDURE `test`.`sp_returns_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_loaded('pdo_mysql')) {
// If not loaded we could try loading it manually
$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
if (!@dl($prefix . 'pdo_mysql.' . PHP_SHLIB_SUFFIX)) {
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=$DB_dbName";
$dbOptions = array();

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

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

This should print something like this:
--------------
PDOStatement Object ( [queryString] => CALL sp_returns_string(@?) )
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("CALL sp_returns_string(?)");
$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 2491
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_returns_string`$$
CREATE PROCEDURE `test`.`sp_returns_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_loaded('pdo_mysql')) {
// If not loaded we could try loading it manually
$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
if (!@dl($prefix . 'pdo_mysql.' . PHP_SHLIB_SUFFIX)) {
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=$DB_dbName";
$dbOptions = array();

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

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

This should print something like this:
--------------
PDOStatement Object ( [queryString] => CALL sp_returns_string(@?) )
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("CALL sp_returns_string(?)");
$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
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 <<<<<<<<<<<<<<< ...
9
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...
2
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...
1
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...
2
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...
0
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...
4
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...
3
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...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.