For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2007 > PDO stored procedures php5.1 mysql5









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PDO stored procedures php5.1 mysql5
gxjw-3301@salzburg-online.at

2007-02-19, 7:57 am

Hello,

I've some problems with calling stored procedures.
When I try to execute the demonstration example on php.net I get no result, but
it works with normal SQL-commandqueries

software: MAMP-package: php 5.1.6, mysql 5.0.19, apache 2.0.59

my stored procedure is for this example returns a string:
CREATE PROCEDURE stringi(OUT result VARCHAR(30)) BEGIN SELECT text INTO result
FROM checker WHERE id = 1;

it works with sql queries like: 'CALL stringi(@a)' - 'SELECT @a'



so the stored procedure should be working correctly, or did i miss something?
Thanks ahead for any advise!


--------------------------------------------


the first code is the one from php.net that doesn't work:
code-output: "procedure returned mysql"

try{
$dbh = new PDO('mysql:host=localhost;dbname=test', 'user', 'password');


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

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

print "procedure returned $return_value\n";



echo $dbh->getAttribute(PDO::ATTR_DRIVER_NAME);

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



this is the example described above that works
output: "Array ( [@a] => baer [0] => baer ) mysql"


try{
$dbh = new PDO('mysql:host=localhost;dbname=test', 'user', 'password');

$dbh->query('CALL stringi(@a)');

foreach($dbh->query('SELECT @a') as $foo)
print_r($foo).'</ br>';

echo $dbh->getAttribute(PDO::ATTR_DRIVER_NAME);

}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com