我有一个php脚本,由ajax以4秒的间隔一次又一次地调用。
try {
$conn_p = new PDO("pgsql:host=$db_host;dbname=$db_dbname", $db_user, $db_password);
} catch(PDOException $e) {
//$e->getMessage();
}
function abc($id)
{
global $conn_p;
$st = "select * from table where id=:id";
$sqlst=$conn_p->prepare($st);
$bindParamArray=array("id"=>$id);
$sqlst->execute($bindParamArray);
$row=$sqlst->fetch();
return $row;
}
function xyz($no)
{
global $conn_p;
$st= "select * from table2 where no=:no and display='Y'";
$sqlst=$conn_p->prepare($st);
$bindParamArray=array(':no' => $no);
$sqlst->execute($bindParamArray);
$row=$sqlst->fetch();
return $row;
}
function abc($id)
{
global $conn_p;
$st = "select * from table where id=:id";
$sqlst=$conn_p->prepare($st);
$bindParamArray=array("id"=>$id);
$sqlst->execute($bindParamArray);
$row=$sqlst->fetch();
return $row;
}
function getData()
{
global $conn_p;
$st= "select * from table2";
$sqlst=$conn_p->prepare($st);
$sqlst->execute();
$row=$sqlst->fetchAll();
return $row;
}
........same other functions
$data = getData();
foreach ($data as $dd) {
$abc[] = abc($dd['id']);
$xyz[] = xyz($dd['no']);
//some other manipulations......
}
echo json_encode(array('data1'=>$abc,'data2'=>$xyz));
运行sql命令时
select * from pg_stat_activity
显示多个连接。(由我的服务器管理员告诉我)
现在我的问题是:
答案 0 :(得分:1)
一些建议:
答案 1 :(得分:0)
这是我在课堂上用于postgresql的内容 它与mysql相同。
$this->dsn = $this->driver . ':host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->name;