语法错误PDO过程调用

时间:2013-05-31 03:33:14

标签: php postgresql stored-procedures pdo

以下是关于postgresql的程序声明。

CREATE OR REPLACE FUNCTION Treasure.RecordReview
(huntId INTEGER, playerName VARCHAR, pTime VARCHAR, pRate VARCHAR, pDesc VARCHAR, OUT status BOOLEAN ) AS $$
DECLARE
status BOOLEAN;
cur_stat_value INTEGER;
BEGIN

INSERT INTO Treasure.review VALUES(huntId, playerName, pTime, pRate, pDesc);

SELECT stat_value INTO cur_stat_value
FROM TreasureHunt.playerstats
WHERE player = $2 AND stat_name = 'review_posts';

IF(cur_stat_value > 0) THEN UPDATE Treasure.playerstats SET stat_value = stat_value + 1 WHERE player = $2 AND stat_name = 'review_posts'; 
ELSE INSERT INTO Treasure.playerstats VALUES($2, 'review_posts',1);
END IF;

status := true;

END;
$$ LANGUAGE plpgsql;

以下是使用PDO访问程序的php代码。

$current_time = date('Y-m-d G:i:s');
$rating = $_POST['rate'];
$desc = $_POST['desc'];
$status;

$cstmt = $conn->prepare("CALL Treasure.RecordReview(?,?,?,?,?,?)");
$cstmt->bindParam(1, $hunt);
$cstmt->bindParam(2, $user);
$cstmt->bindParam(3, $current_time);
$cstmt->bindParam(4, $rating);
$cstmt->bindParam(5, $desc);
$cstmt->bindParam(6, $status, PDO::PARAM_BOOL|PDO::PARAM_INPUT_OUTPUT);
$cstmt->execute();

当我执行我的代码时,它会返回错误:

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "CALL" LINE 1: CALL Treasure.RecordReview($1,$2,$3,$4,$5,$6) ^

[编辑] 按照建议将“CALL”更改为“SELECT”。但是又出现了另一个错误。

Error Connecting to Database: SQLSTATE[08006] [7] FATAL: remaining connection slots are reserved for non-replication superuser connections

然后

SQLSTATE[42883]: Undefined function: 7 ERROR: function treasure.recordreview(unknown, unknown, unknown, unknown, unknown, unknown) does not exist LINE 1: SELECT Treasure.RecordReview($1,$2,$3,$4,$5,$6); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

1 个答案:

答案 0 :(得分:3)

你不使用CALL在PostgreSQL中执行一个函数,使用SELECT

$cstmt = $conn->prepare("select Treasure.RecordReview(?,?,?,?,?,?)");