//数据库链接代码 db.class.php
/**
* 数据库构造函数
*/
public function __construct() {
// $this->memcache = $this->getMemecacheObject();
/** 单一实例 PDO对象 */
if (!self::$PDOInstance) {
$this->config = json_decode(file_get_contents(ROOT_ADDR."/private/config/db.json"), true);
$config = $this->config;
$host = $config["data_base"]["db_host"];
$dbname = $config["data_base"]["db_name"];
$port = $config["data_base"]["db_port"];
$username = $config["data_base"]["db_user"];
$password = $config["data_base"]["db_pwd"];
if ($config["data_base"]["db_host"] != 'localhost') {
$hosturl = "host=$host;";
}
try
{
self::$PDOInstance = new PDO("pgsql:"
. $hosturl
. "port=$port;"
. "dbname=$dbname;"
, $username
, $password
, array(
PDO::ATTR_PERSISTENT => true,
)
);
} catch (Exception $ex) {
$tools = new tools();
$path = $tools->log("数据库初始化失败,已强制断开链接。<br/>抓取到的异常栈如下:<br/><pre>" . print_r($ex, true) . "</pre>", 'db');
header("Content-type:text/html;charset=utf-8");
if ($config["SYSTEM"]["DEBUG"]) {
echo "数据库初始化失败,已强制断开链接。<br/>详细信息请访问{$path}文件日志";
} else {
echo "数据库初始化失败,请联系系统管理员。";
}
die();
}
try {
self::$PDOInstance->query("SET client_encoding='UTF-8';");
self::$PDOInstance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $exc) {
$this->pdo=NULL;
$doc = <<<DOC
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="layer/jquery-1.11.1.min.js"></script>
<script src="layer/layer.js"></script>
<head>
<body>
DOC;
print $doc;
$info=L('服务器变更请刷新');
print("<script>layer.msg('".$info."', {icon: 2,time: 30000},function(){location.reload();});</script>");
print('</body></html>');
self::$PDOInstance=NULL;
exit();
}
}
$this->pdo = self::$PDOInstance;
$this->getconnect_server();
}
//每个模块需要做数据库操作时,model层会去执行下父类(db.class.php)的构造方法 然后进行数据库操作
public function __construct($data) {
parent::__construct();
}
[root@asg omp]# ps -aux | grep post | grep omp
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
postgres 31717 0.1 0.2 199876 8864 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43255) idle
postgres 31725 0.2 0.2 200032 9964 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43256) idle
postgres 31787 0.0 0.1 199568 5496 ? Ss 16:25 0:00 postgres: ompuser OMPDB [local] idle
[root@asg omp]# ps -aux | grep post | grep omp
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
postgres 31717 0.0 0.2 199876 8864 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43255) idle
postgres 31725 0.1 0.2 200032 9964 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43256) idle
postgres 31787 0.0 0.1 199568 5496 ? Ss 16:25 0:00 postgres: ompuser OMPDB [local] idle
postgres 32234 0.2 0.2 199924 8352 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43257) idle
postgres 32254 0.1 0.1 199724 7516 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43258) idle
[root@asg omp]# ps -aux | grep post | grep omp
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
postgres 2954 0.0 0.1 199660 6752 ? Ss 16:30 0:00 postgres: ompuser OMPDB asg.localdomain(43261) idle
postgres 2956 0.0 0.1 199724 7496 ? Ss 16:30 0:00 postgres: ompuser OMPDB asg.localdomain(43262) idle
postgres 2966 0.2 0.2 200216 8632 ? Ss 16:30 0:00 postgres: ompuser OMPDB asg.localdomain(43263) idle
postgres 2967 0.0 0.1 199660 6748 ? Ss 16:30 0:00 postgres: ompuser OMPDB asg.localdomain(43264) idle
postgres 2968 0.0 0.1 199660 6760 ? Ss 16:30 0:00 postgres: ompuser OMPDB asg.localdomain(43265) idle
postgres 31717 0.0 0.2 200068 9144 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43255) idle
postgres 31787 0.0 0.1 199568 5496 ? Ss 16:25 0:00 postgres: ompuser OMPDB [local] idle
postgres 32234 0.0 0.2 199924 8352 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43257) idle
postgres 32254 0.0 0.1 199724 7516 ? Ss 16:25 0:00 postgres: ompuser OMPDB asg.localdomain(43258) idle