2017-04-10 39 views
0

我與兩種類型 1)如何調用在laravel PostgreSQL的存儲過程5

DB::statement('call abc_cmw("$ipaddress","$cname","$recvd_date","$language","$address1","$address2","$address3","$pincode","$mobileno","$amobileno","$email_address","$idproofdetail","$Description","$remedies","$gretype","$fcount","$content1","$content2","$district_problem","$city_problem", "$block_problem","$village_problem","$username","$sugg_demand","$dept_name","$indiv_grp","$ac_problem")'); 

2)

DB::select('exec abc_cmw("$ipaddress","$cname","$recvd_date","$language","$address1","$address2","$address3","$pincode","$mobileno","$amobileno","$email_address","$idproofdetail","$Description","$remedies","$gretype","$fcount","$content1","$content2","$district_problem","$city_problem", "$block_problem","$village_problem","$username","$sugg_demand","$dept_name","$indiv_grp","$ac_problem")'); 

但兩種方式具有相同的錯誤

QueryException in Connection.php line 647: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "call" LINE 1: call abc_cmw("$ipaddress","$cname","$re...^(SQL: call abc_cmw("$ipaddress","$cname","$recvd_date","$language","$address1","$address2","$address3","$pincode","$mobileno","$amobileno","$email_address","$idproofdetail","$Description","$remedies","$gretype","$fcount","$content1","$content2","$district_problem","$city_problem", "$block_problem","$village_problem","$username","$sugg_demand","$dept_name","$indiv_grp","$ac_problem"))

回答

0

測試在PostgreSQL中,使用SELECT子句調用函數,例如:SELECT func()

由於SQL注入的可能性,應避免直接插入SQL參數。使用綁定改爲:

DB::statement('SELECT abc_cmw(?, ?, ?)', [$param1, $param2, $param3]); 

DB::statement('SELECT abc_cmw(:param1, :param2, :param3)', [ 
    'param1' => $param1, 
    'param2' => $param2, 
    'param3' => $param3 
]); 
+0

我想在您的解決方案問號知道有列名替換或者我需要instert問號每列? –

+0

您可以使用命名的綁定(第二個示例)或數組綁定(第一個示例)。如果您更喜歡數組綁定,請爲每列添加問號。 – AlexM

+0

好吧讓我試試第一個例子 –