顯示具有 codeigniter 標籤的文章。 顯示所有文章
顯示具有 codeigniter 標籤的文章。 顯示所有文章

2014年7月9日 星期三

codeigniter 設定 Medoo database framework為library

Medoo為一個蠻好用的database framework 一直很想把它加進codeigniter使用 首先file medoo.php in application/libraries:
<?php
class medoo 
{
   protected $database_type = 'mysql';
   // For MySQL, MariaDB, MSSQL, Sybase, PostgreSQL, Oracle
   protected $server = 'localhost';
   ......略
}
之後就能夠直接取用此工具囉!~ ex:
<?php
Controller admin.php in application/controllers

class Admin extends CI_Controller
{
    function index()
    {
 $this->load->library('medoo','datebase_name'); //第二欄位可設params
 $data = $this->medoo->select('table_name', '*');
    }
}

codeigniter 備份目前網站資料庫

因為一些因素必須要撰寫公司網站資料庫備份的排程
所以筆記一下以做為以後方便查找:

在controller:
<?php
class Mybackup extends MY_Controller {

 public function index(){
  $this->load->dbutil();
  // Backup your entire database and assign it to a variable
  $backup =& $this->dbutil->backup(); 
  // Load the file helper and write the file to your server
  $this->load->helper('file');

  if (!write_file('./mybackup.zip', $backup)){
     echo 'Unable to write the file';
  } else{
   echo 'File written!';
  }
   
 }


} 
 
網站目錄(預設根目錄)可取得..mybackup.zip這個檔案囉