作者joedenkidd (优质的蓝色射手)
看板PHP
标题Re: [请益] PHP+postgreSQL
时间Mon Dec 31 18:47:37 2012
$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
1F:推 ob556:还是不行QQ 01/01 18:16
2F:→ joedenkidd:database权限有设定吗?设定给你要连的帐号? 01/02 12:48