本篇内容主要讲解“怎么用pgsql pdo php操作类”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用pgsql pdo php操作类”吧!
核心代码:
/* *pgsql类 */ class pgdb { public $pdo; public static $PDOInstance; public $config; public $data; public $filed = '*'; public $table; public $limit; public $order; public $where; public $left; const LOGIN = 7; const USER = 1; const GROUP = 2; const USERGROUP = 3; const LOG = 6; const WARING = 1; const ERROR = 2; const INFO = 0; public function __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 = new PDO("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("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>'); exit(); } } $this->pdo = self::$PDOInstance; } }
到此,相信大家对“怎么用pgsql pdo php操作类”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。