簡單的pgsql pdo php操作類實(shí)現(xiàn)代碼
更新時(shí)間:2016年08月25日 23:48:35 投稿:mdxy-dxy
這篇文章主要介紹了簡單的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 = "數(shù)據(jù)庫初始化失敗,已強(qiáng)制斷開鏈接。<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('服務(wù)器變更請刷新');
print("<script>layer.msg('".$info."', {icon: 2,time: 30000},function(){location.reload();});</script>");
print('</body></html>');
exit();
}
}
$this->pdo = self::$PDOInstance;
}
}
相關(guān)文章
php中file_get_content 和curl以及fopen 效率分析
關(guān)于file_get_content 和curl以及fopen 的效率問題,小編比較傾向于使用curl來訪問遠(yuǎn)程url。Php有curl模塊擴(kuò)展,功能很是強(qiáng)大。沒事可以研究一下。2014-09-09
PHP實(shí)現(xiàn)本地圖片轉(zhuǎn)base64格式并上傳
這篇文章主要介紹了PHP實(shí)現(xiàn)本地圖片轉(zhuǎn)base64格式并上傳,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
PHP解析RuoYi框架實(shí)現(xiàn)Token解密詳解
這篇文章主要介紹了PHP解析RuoYi框架實(shí)現(xiàn)Token解密,同時(shí)本篇文章對RuoYi若依框架的使用進(jìn)行簡單的介紹,它和php的fastadmin框架非常類似,是可以根據(jù)數(shù)據(jù)庫表自動的生成一個完整的管理后臺2022-10-10
php實(shí)現(xiàn)計(jì)算百度地圖坐標(biāo)之間距離的方法
這篇文章主要介紹了php實(shí)現(xiàn)計(jì)算百度地圖坐標(biāo)之間距離的方法,涉及php字符串、數(shù)組及數(shù)學(xué)運(yùn)算的相關(guān)技巧,需要的朋友可以參考下2016-05-05
PHP下載采集圖片到本地的方法詳解【可忽略ssl認(rèn)證】
這篇文章主要介紹了PHP下載采集圖片到本地的方法,結(jié)合實(shí)例形式詳細(xì)分析了php基于Curl遠(yuǎn)程獲取遠(yuǎn)程圖片資源到本地的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2023-07-07

