秋凉2018-03-14 21:10:44
## public $insertId = null;
# public $num = 0;
私人靜態$instance = null;
## 私人$conn = null;
私有函數 __construct($params){
$this->dbConfig = array_merge($this->dbConfig,$params);
# $this->conncet();
}
# 私人函數__clone(){
# }
公用函數getInstance(){
if(!self::$instance instanceof self){
self::$instance = new self();
}
return self::$instance;
}
public function connect(){
try{
## $dsn = " { $this->dbConfig['db']}:{$this->dbConfig['host']}; port = {$this->dbConfig['port']};字元集= {$this->dbConfig['charset']}"; $this->conn = new pdo($dsn,$this->dbConfig['user '],$ this->dbConfig['password']); } catch(PDOExecption $e){ die("資料庫連線失敗". $e->getMessage ()); } }//完成資料表的寫入操作新增更新刪除# //傳回出行的記錄如果新增也回傳新增主鍵id public function exec($sql){ $num = $this->conn->exec($sql );# / / 如果有旅行的記錄 if($num>0){ // 如果是新增操作初始化新增主鍵ID的屬性 if(null ! ==$this->conn->lastInsertId()){ $this->insertId = $this->conn->lastInsertId( ); } $this->num = $rum;//返回旅行的記錄 }else{ $error = $this->conn->errorInfo(); //取得最後操作的錯誤訊息 【0】錯誤標識符【1】錯誤代碼【2】錯誤訊息 print '操作失敗'.$error[0].':'.$error[1 ].':'.$error[2]; } }
## //取得單一查詢資訊
} public function fetchALL($sql){ return $this->conn->query($sql)->fetch(PDO::FETCH_ASSOC );
}}#