我正在尝试设置一个包含一些数据库函数的PHP类。所有函数都使用相同的DB,所以我想在类中定义登录信息/连接。
<?php
Class DBcalls {
private static $dbconn = pg_connect("host=localhost port=5432 dbname=dbnamehere user=usernamejere password=1234567");
function adbcallfunc($called){
$result = pg_prepare($dbconn, "adbcallfunc", 'select somecolumn from table where somecolumn = $1');
$result = pg_execute($dbconn, "adbcallfunc", array($called));
$GetResult = @pg_fetch_array($result);
$key = 'othercolumn';
$wantedresults = $GetResult[$key];
return $totalviews;
}
}
然后我会调用这个函数:
$query = new DBcalls;
$query = $query->IPViewCount('foo');
echo $query;
有人可以解释如何使这项工作,或更好的方式存储此信息。