2013-05-31 59 views
1

下面是postgresql上的過程聲明。語法錯誤PDO過程調用

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」,以 「選擇」 的建議。但另一個錯誤出現了。

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. 

回答

3

不要使用CALL執行PostgreSQL中的功能,使用SELECT

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

感謝,但我得到了另一種錯誤的。 '連接數據庫時出錯:SQLSTATE [08006] [7]致命:其餘連接槽保留給非複製超級用戶連接' – Pelang

+2

這是完全不同的東西。聽起來像你有一堆殭屍數據庫連接掛在:http://stackoverflow.com/q/11847144/479863 –