Re: [請益] PHP+postgreSQL

看板PHP作者 (優質的藍色射手)時間13年前 (2012/12/31 18:47), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
$server_link=pg_connect("dbname=$dbname user=$user port=$port"); $sql="$sql"; $sql_exec=pg_exec($server_link,$sql); 你用上面的語發看看吧!我都是這樣子連的,我的port是5432 ※ 引述《ob556 (^o^OoB)》之銘言: : 之前用Mysql+PHP都沒問題,但這次改用postgresql就一直抓不到資料庫的資料 : 以下是我的程式碼: : $con = pg_connect("host=$hostname port=$port dbname=$database user=$username : password=$password") or die ("Could not connect to server\n"); : // array for JSON response : $response = array(); : //搜尋主選單項目 : $query = "SELECT * FROM category"; : $sql = pg_query($con,$query) or die("Cannot execute query!"); : if (pg_num_rows($sql) > 0) { : // looping through all results : // subcategories node : $response["categories"] = array(); : while ($row = pg_fetch_array($sql)) { : // temp user array : $category = array(); : $category["category_ID"] = $row["category_ID"]; : $category["category_name"] = $row["category_name"]; : // push single subcategory into final response array : array_push($response["categories"], $category); : } : // success : $response["success"] = 1; : // echoing JSON response : echo json_encode($response); : } else { : // no category found : $response["success"] = 0; : $response["message"] = "No subcategory found"; : // echo no users JSON : echo json_encode($response); : } : 結果每次連結到PHP都出現"Cannot execute query!" : 我有把$query的內容直接放到phppgadmin裡面用SQL查詢,是沒問題的 : 所以一直搞不清楚問題到底出在哪 : 希望有好心人能教教我>< : 謝謝!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.12.157

01/01 18:16, , 1F
還是不行QQ
01/01 18:16, 1F

01/02 12:48, , 2F
database權限有設定嗎?設定給你要連的帳號?
01/02 12:48, 2F
文章代碼(AID): #1GuMrAsY (PHP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
2
4
完整討論串 (本文為第 2 之 2 篇):
2
4
文章代碼(AID): #1GuMrAsY (PHP)