Stored Procedures, MySQL and PHP

前端 未结 5 1583
故里飘歌
故里飘歌 2020-11-30 08:35

The question is a fairly open one. I\'ve been using Stored Procs with MS SQLServer for some time with classic ASP and ASP.net and love them, lots.

I have a small hob

5条回答
  •  广开言路
    2020-11-30 08:54

    @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";
    

提交回复
热议问题