Fix Database class
This commit is contained in:
parent
79967cc2c3
commit
eb56544d1d
@ -15,7 +15,8 @@ use UElearning\Database\Exception;
|
|||||||
/**
|
/**
|
||||||
* 資料庫操作抽象類別
|
* 資料庫操作抽象類別
|
||||||
*
|
*
|
||||||
* 請根據一個資料表創建一個類別,並繼承此類別。所有對於資料表的操作(包含查詢、新增、修改、刪除),一律使用新創已繼承的類別物件。
|
* 請根據一個資料表創建一個類別,並繼承此類別。
|
||||||
|
* 所有對於資料表的操作(包含查詢、新增、修改、刪除),一律使用新創已繼承的類別物件。
|
||||||
*
|
*
|
||||||
* 基本的操作方式例如:
|
* 基本的操作方式例如:
|
||||||
*
|
*
|
||||||
@ -136,7 +137,11 @@ abstract class Database {
|
|||||||
|
|
||||||
// 檢查是否有支援所設定的DBMS
|
// 檢查是否有支援所設定的DBMS
|
||||||
if($this->db_type == 'mysql') {
|
if($this->db_type == 'mysql') {
|
||||||
$this->connDB = new MySQLDB($this->db_name, $this->db_host, $this->db_port, $this->db_user, $this->db_passwd);
|
$this->connDB = new MySQLDB($this->db_name
|
||||||
|
, $this->db_host
|
||||||
|
, $this->db_port
|
||||||
|
, $this->db_user
|
||||||
|
, $this->db_passwd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Exception\DatabaseNoSupportException($this->db_type);
|
throw new Exception\DatabaseNoSupportException($this->db_type);
|
||||||
|
@ -33,12 +33,13 @@ class MySQLDB extends PDO {
|
|||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct($dbname, $host, $port, $user, $passwd){
|
public function __construct($dbname, $host, $port, $user, $passwd){
|
||||||
parent::__construct("mysql:dbname=".$dbname.";host:".$host."port=".$port.";
|
parent::__construct('mysql:dbname='.$dbname
|
||||||
charset=utf8", DB_USER, DB_PASS);
|
.';host:'.$host.';port='.$port
|
||||||
|
.';charset=utf8', DB_USER, DB_PASS);
|
||||||
|
|
||||||
//配合PHP< 5.3.6 PDO沒有charset用的
|
//配合PHP< 5.3.6 PDO沒有charset用的
|
||||||
//參考: http://gdfan1114.wordpress.com/2013/06/24/php-5-3-6-%E7%89%88-pdo-%E9%85%8D%E5%90%88%E5%AD%98%E5%8F%96%E8%B3%87%E6%96%99%E5%BA%AB%E6%99%82%E7%9A%84%E4%B8%AD%E6%96%87%E5%95%8F%E9%A1%8C/
|
//參考: http://gdfan1114.wordpress.com/2013/06/24/php-5-3-6-%E7%89%88-pdo-%E9%85%8D%E5%90%88%E5%AD%98%E5%8F%96%E8%B3%87%E6%96%99%E5%BA%AB%E6%99%82%E7%9A%84%E4%B8%AD%E6%96%87%E5%95%8F%E9%A1%8C/
|
||||||
$this->exec("set names utf8");
|
$this->exec('set names utf8');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,9 @@ class MySQLDB extends PDO {
|
|||||||
public function ErrorMsg(){
|
public function ErrorMsg(){
|
||||||
$err = parent ::errorinfo();
|
$err = parent ::errorinfo();
|
||||||
if( $err[0]!='00000' ){
|
if( $err[0]!='00000' ){
|
||||||
return array('errorCode'=>$err[0],'number'=>$err[1],'message'=>$err[2]);
|
return array('errorCode'=>$err[0]
|
||||||
|
,'number'=>$err[1]
|
||||||
|
,'message'=>$err[2]);
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user