简单的pgsql pdo php操作类实现代码
核心代码:
/* *pgsql类 */ classpgdb{ public$pdo; publicstatic$PDOInstance; public$config; public$data; public$filed='*'; public$table; public$limit; public$order; public$where; public$left; constLOGIN=7; constUSER=1; constGROUP=2; constUSERGROUP=3; constLOG=6; constWARING=1; constERROR=2; constINFO=0; publicfunction__construct(){ if(!self::$PDOInstance){ $this->config=json_decode(file_get_contents("./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=newPDO("pgsql:" .$hosturl ."port=$port;" ."dbname=$dbname;" ,$username ,$password ,array( PDO::ATTR_PERSISTENT=>true, ) ); }catch(Exception$ex){ header("Content-type:text/html;charset=utf-8"); $error="数据库初始化失败,已强制断开链接。<br/>抓取到的异常栈如下:<br/><pre>".print_r($ex,true)."</pre>"; die($error); } try{ self::$PDOInstance->query("SETclient_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 <!DOCTYPEhtml> <html> <head> <metacharset="UTF-8"> <scriptsrc="layer/jquery-1.11.1.min.js"></script> <scriptsrc="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>'); exit(); } } $this->pdo=self::$PDOInstance; } }