0

私はこのSPを使用していますが、mysqlワークベンチを使用すると両方の結果が得られます。

CREATE PROCEDURE SP(IN _start INT,IN _end INT,INOUT _count INT)
BEGIN

   SET _count = (SELECT COUNT(*) FROM tbl);

   SET @qry = CONCAT('select * from tbl limit ', _start, ',', _end);

   PREPARE stmt FROM @qry;
   EXECUTE stmt;
   DEALLOCATE PREPARE stmt;

END

しかし、PDOで使用すると、このエラーが返されます

$c=0;
$stmt = $this->_dbc->getConnection()->prepare("CALL SP(0,10,:count)");
    $stmt->bindParam(":count",$c,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,0);
    $stmt->execute();
    return $c;
PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1414 OUT or INOUT argument 3 for routine db22.SP is not a variable or NEW pseudo-variable in BEFORE trigger

しかし、変更すると

$this->_dbc->getConnection()->prepare("CALL SP(0,10,**:count**)");

$this->_dbc->getConnection()->prepare("CALL SP(0,10,@count)");

エラーは返されませんが、常にカウントは0になります。

  1. :countと@countの違いは何ですか?
  2. pdoを介して正確なカウントを取得する方法は?
4

1 に答える 1

4

次の回避策を実行できます。

$dbh = $this->_dbc->getConnection()
$stmt = $dbh->prepare("CALL SP(0,10,@count)");
$stmt->execute();

$sql = "SELECT @count AS count";
$stmt = $dbh->prepare($sql);
$stmt->execute();

詳細については、 http: //www.php.net/manual/en/pdo.prepared-statements.php#101993を参照してください。

于 2012-04-20T18:49:22.667 に答える