- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码:
require 'dataload.php';
function get_objects($where,$name=false) {
global $epsg, $cnt_array;
$db = Dataload::getDB();
$columns="osm_id, ST_AsGeoJSON(ST_Transform(way,4326)) as way2, name, ward, \"healthcare:speciality\", information, description, social_facility, \"social_facility:for\", capacity, operator, official_name, official_status, phone, website, \"addr:full\", \"addr:city\", \"addr:district\", \"addr:postcode\", opening_hours, \"addr:hamlet\", \"addr:street\", fax, email, allhuman, adulthuman, childhuman, \"healthcare:heart\", \"healthcare:mind\", \"healthcare:maternity_light\", \"healthcare:maternity_hard\", \"healthcare:dtp\", \"ward:speciality_gynaecology\", \"ward:speciality_maternity\", \"ward:speciality_infectious_diseases\", \"ward:speciality_neurology\", \"ward:speciality_paediatrics\", \"ward:speciality_general\", \"ward:speciality_surgery\", \"internet_access:operator\", \"internet_access:speed\", \"wifi_access:ssid\"";
$query="select ".$columns." from test_point where ".$where;
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
$geojson = array(
'type' => 'FeatureCollection',
'features' => array(),
'crs' => array(
'type' => 'EPSG',
'properties' => array('code' => '4326')
)
);
while($myrow = pg_fetch_assoc($result)) {
$gos18_work = array();
if($name=="gos18") {
$query_gos18_work = "select * from gos18_work where obj=".$myrow["osm_id"];
$result_gos18_work = pg_query($query_gos18_work);
if (!$result_gos18_work) {
echo "Problem with query " . $query_gos18_work . "<br/>";
echo pg_last_error();
exit();
}
while($myrow_gos18 = pg_fetch_assoc($result_gos18_work)) {
$gos18_work[] = array(
blah=>blah
);
}
}
$feature = array(
'type' => 'Feature',
'id' => $myrow["osm_id"],
'layer' => $epsg,
'geometry' => json_decode($myrow["way2"], true),
'geometry_name' => 'way',
'properties' => array(
'name' => $myrow["name"],
)
);
// Add feature array to feature collection array
array_push($geojson['features'], $feature);
}
// Close database connection
pg_close($db);
}
if(blah) ......get_objects($where);....
数据加载(获取数据库的类):
public static function getDB() {
return pg_connect('host=notlocalhost port=5432 user=user password=password dbname=dbname')
or die("not connect".pg_last_error());
}
如果 DB 连接到本地主机,但另一台服务器(没有 DB 的复制站点)返回错误,则此方法有效:
Warning: pg_close() expects parameter 1 to be resource, boolean given in my.php on line....
但是!如果注释 pg_close()
这工作没有任何错误并从 DB 返回结果。
最佳答案
pg_connect 的 php 手册中的评论:
Beware about writing something like
<?php
function getdb_FAILS() {
return pg_connect("...") or die('connection failed');
}
?>It will return a boolean. This will appear to be fine if you don't use the return value as a db connection handle, but will fail if you do.
Instead, use:
<?php
function getdb() {
$db = pg_connect("...") or die('connection failed');
return $db;
}
?>which actually returns a handle.
希望这对您有所帮助。
关于php - 连接到 postgres 时出错(pg_close),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48769080/
我有以下代码: require 'dataload.php'; function get_objects($where,$name=false) { global $epsg, $cn
当使用 pg_pconnect 连接从 php 连接到 postgres 时,pg_close 是否: 真的关闭连接(破坏持久效果)? 将连接移交给 pconnect 池? 最佳答案 与PHP.ini
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: using mysql_close() 是否需要 mysql_close 和 pg_close? 在某些脚本
我是一名优秀的程序员,十分优秀!