Stored Procedures, MySQL and PHP

@michal kralik – unfortunately there’s a bug with the MySQL C API that PDO uses which means that running your code as above with some versions of MySQL results in the error:

“Syntax error or access violation: 1414 OUT or INOUT argument $parameter_number for routine $procedure_name is not a variable or NEW pseudo-variable”.

You can see the bug report on bugs.mysql.com. It’s been fixed for version 5.5.3+ & 6.0.8+.

To workaround the issue, you would need to separate in & out parameters, and use user variables to store the result like this:

$stmt = $dbh->prepare("CALL sp_takes_string_returns_string(:in_string, @out_string)");
$stmt->bindParam(':in_string', 'hello'); 

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

// fetch the output
$outputArray = $this->dbh->query("select @out_string")->fetch(PDO::FETCH_ASSOC);

print "procedure returned " . $outputArray['@out_string'] . "\n";

Leave a Comment