修正 ci3 DB繼承

注意:
因為我認定 ci核心 應該都要放在 core/底下 所以我有再次修正
另外是我們使用的 並不是 CI_DB_mysql_driver 是 CI_DB_mysqli_driver 所以 有再次修正

<?php
/*
 * 參考文章: https://github.com/bcit-ci/CodeIgniter/wiki/Extending-Database-Drivers
 * 小毛: 改寫了 讀取 database CI_DB_mysqli_driver 的核心繼承 資料夾請放在 core
*/
class MY_Loader extends CI_Loader {

	public function database($params = '', $return = FALSE, $query_builder = NULL)
	{
		// Grab the super object
		$CI =& get_instance();

		// Do we even need to load the database class?
		if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id))
		{
			return FALSE;
		}

		require_once(BASEPATH.'database/DB.php');

		// Load the DB class
		$db =& DB($params, $query_builder);

		$my_driver = config_item('subclass_prefix').'DB_'.$db->dbdriver.'_driver';
		$my_driver_file = APPPATH.'core/'.$my_driver.'.php';

		if (file_exists($my_driver_file)) {
			require_once($my_driver_file);
			$db_obj = new $my_driver(get_object_vars($db));
			$db=& $db_obj;
		}

		if ($return === TRUE)
		{
			return $db;
		}

		// Initialize the db variable. Needed to prevent
		// reference errors with some configurations
		$CI->db = '';

		// Load the DB class
		$CI->db =& $db;
		return $this;
	}

}
<?php
class MY_DB_mysqli_driver extends CI_DB_mysqli_driver {

	function __construct($params){
		parent::__construct($params);
	}
	
	public function test()
	{
		var_dump('expression');
	}

}

參考資料:https://github.com/bcit-ci/CodeIgniter/wiki/Extending-Database-Drivers

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *