亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

pg_prepare 和 pg_fetch_object

pg_prepare 和 pg_fetch_object

PHP
繁星點點滴滴 2022-06-17 17:01:02
我正在使用 postgres 擴展在 php 中準備一個語句。然后我嘗試使用pg_fetch_object.從準備好的語句中沒有返回任何行,但它應該。我還收到以下警告:警告:pg_prepare(): Query failed: ERROR: Prepared statement "parking" already exists in C:\xampp\htdocs\map\MapMarkers.php on line 33$devices_query = pg_query($conn, "SELECT applications.name category, devices.* FROM app_as.application applications, app_as.device devices WHERE applications.id = devices.application_id");//variables are bound in the loop$parking_pst = pg_prepare($conn, "parking", "SELECT distinct on (name) name,application_name,longitude,latitude,parking_car_status status,received_at FROM V_DEVICE_PARKING WHERE name = $1");while ($devices = pg_fetch_object($devices_query)) {        pg_execute($conn, "parking",[$devices->name]);        while ($parking = pg_fetch_object($parking_pst)) {            $devices->parking_car_status = $parking->parking_car_status;        }    $data['DEVICES'][] = $devices;}
查看完整描述

1 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

您收到此錯誤/警告是因為您正在pg_fetch_object()通話pg_prepare()。本質上,每次在while()循環中迭代時,您都會再次調用pg_prepare(),無意中嘗試創建一個新的準備好的語句,稱為“停車”。


您真正要做的是獲得結果,pg_execute()然后使用以下方法提取結果pg_fetch_object():


$devices_query = pg_query($conn, "SELECT applications.name category, devices.* FROM app_as.application applications, app_as.device devices WHERE applications.id = devices.application_id");


$prepare_result = pg_prepare($conn, "parking", "SELECT distinct on (name) name,application_name,longitude,latitude,parking_car_status status,received_at FROM V_DEVICE_PARKING WHERE name = $1");


// Maybe process $prepare_result as needed here


while ($devices = pg_fetch_object($devices_query)) {


        $execute_result = pg_execute($conn, "parking", [$devices->name]);


        while ($parking = pg_fetch_object($execute_result)) {

            $devices->parking_car_status = $parking->parking_car_status;

        }


    $data['DEVICES'][] = $devices;

}


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號