'mysql', * 'host' => 'localhost', * 'port' => '3306', * 'user' => 'user', * 'password' => '123456', * 'dbname' => 'chu-elearning', * 'prefix' => 'chu_' * )); * * 實際範例可參考 `DBAdmin` 類別的說明文件 * * @author Yuan Chiu * @version 2.0.0 * @subpackage Database */ abstract class Database { /** * 資料庫伺服器位址 * @type string */ protected $db_host; /** * 資料庫伺服器連結埠 * @type string */ protected $db_port; /** * 資料庫帳號 * @type string */ protected $db_user; /** * 資料庫密碼 * @type string */ protected $db_passwd; /** * 資料庫名稱 * @type string */ protected $db_name; /** * 資料表前綴字元 * @type string */ protected $db_prefix; // ------------------------------------------------------------------------ /** * 資料庫連結物件 */ protected $connDB; // ======================================================================== /** * 連接資料庫 * * @param array $conf (optional) 資料庫相關參數,格式為: * array( 'type' => 'mysql', * 'host' => 'localhost', * 'port' => '3306', * 'user' => 'user', * 'password' => '123456', * 'dbname' => 'chu-elearning', * 'prefix' => 'chu_' ) * 若不填寫將會直接使用設定在`config.php`的常數 * * @throws MessageBoard\Exception\DatabaseNoSupportException * @author Yuan Chiu * @since 2.0.0 */ public function __construct($conf = null) { // 將資料庫設定資訊帶入 if(isset($conf)) { $this->db_host = $conf['host']; $this->db_port = $conf['port']; $this->db_user = $conf['user']; $this->db_passwd = $conf['password']; $this->db_name = $conf['dbname']; $this->db_prefix = $conf['prefix']; } else { $this->db_host = DB_HOST; $this->db_port = DB_PORT; $this->db_user = DB_USER; $this->db_passwd = DB_PASS; $this->db_name = DB_NAME; $this->db_prefix = DB_PREFIX; } $this->connDB = new MySQLDB($this->db_name , $this->db_host , $this->db_port , $this->db_user , $this->db_passwd); } /** * 轉為完整的資料表名稱(包含前綴字元) * * @param string $tableName 資料表名稱 * @return string 完整的資料表名稱 * * @author Yuan Chiu * @since 2.0.0 */ public function table($tableName) { return $this->db_prefix.$tableName; } /** * 測試資料庫有無連接成功 * * @since 2.0.0 */ public function connectTest() { // TODO: Fill code in } }