Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unable to create/use multiple Database instance in Oil
  • What I trying to achieve
    Create an oil task to upgrade old database structure (DATABASE old_db) to new database structure (DATABASE new_db). For this task, I wrote a Upgrader class and store it in
    /fuel/app/classes/upgrader.php
    

    Here a snippet of Upgrader class
    class Upgrader {
    
     private $db = NULL;
    
     private $run = array (
      'option',
      #'department',
      #'location',
      #'status',
      #'role',
      #'brand',
      #'item',
      #'category',
      #'issue',
      #'user'
       );
    
     public function __construct() {
      $this->$db = \Fuel\Core\Database_MySQL::instance('migrate');
    
      \DB::query('TRUNCATE TABLE `mappers`')->execute();
    
      foreach ($this->run as $run) {
       $method = "down_{$run}";
       echo "Calling {$method}";
       $this->{$method}();
    
       $method = "up_{$run}";
       echo "Calling {$method}";
       $this->{$method}();
       
       echo "Table/Module: {$run} migrated";
       echo "----";
      }
     }
     private function query($sql) {
      return $this->db->query(1, $sql, NULL);
     }
    }
    

    This so far work great if I called it from a controller but when I load it from oil refine I got this following error
    Mior-Muhammad-Zakis-MacBook-Pro:mobife crynobone$ php oil refine aduit:upgrade
    PHP Fatal error:  Cannot redeclare class Fuel\Core\Database in /Users/crynobone/Sites/mobife/fuel/core/classes/database.php on line 18
    Compile Error - Cannot redeclare class Fuel\Core\Database in COREPATH/classes/database.php on line 18
    

    So is there something I'm missing? Or is there a better way to use multiple database connection with FuelPHP?
  • Just tried a different approach by using DB instead but still fail.
    private function query($sql) {
      return \DB::query($sql)->execute('migrate');
     }
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion