Hello Guys,
I'm managing Migrations in my Codeigniter project.
Here is my migration class:
PHP Code:
class Migrate extends CI_Controller
{
public function __construct ()
{
parent::__construct();
$this->load->library('migration');
$this->load->dbforge();
}
public function latest ()
{
$this->migration->latest();
echo $this->migration->error_string() . PHP_EOL;
}
public function reset ()
{
$this->migration->version(0);
echo $this->migration->error_string() . PHP_EOL;
}
public function version ($version = 0)
{
$version = (int) $version;
if ($version == 0) {
die('You need to paas a version greater than zero') . PHP_EOL;
}
$this->migration->version($version);
echo $this->migration->error_string() . PHP_EOL;
}
}
Now, what I would like to do is make sure my controller can be ran by the terminal.
Now all of these functions work, I can set the version, I can reset the migrations or automatically set it to the latest available.
Works Great!
However If i try to execute it from the terminal I.E:
Code:
php index.php migrate latest
I get a horrible error:
mothership:public_html Sherlock$ php index.php migrate latest
Code:
A PHP Error was encountered
Severity: WarningMessage: mysqli::real_connect(): (HY000/2002): No such file or directoryFilename: /Users/Matt/PhpstormProjects/barebones/system/database/drivers/mysqli/mysqli_driver.phpLine Number: 135
Backtrace:
File: /Users/Matt/PhpstormProjects/barebones/application/third_party/MX/Loader.php Line: 109 Function: DB
File: /Users/Matt/PhpstormProjects/barebones/application/third_party/MX/Loader.php Line: 173 Function: _ci_load_library
File: /Users/Matt/PhpstormProjects/barebones/application/controllers/Migrate.php Line: 14 Function: library
File: /Users/Matt/PhpstormProjects/barebones/public_html/index.php Line: 313 Function: require_once
A PHP Error was encountered
Severity: WarningMessage: mysqli::real_connect(): (HY000/2002): No such file or directoryFilename: /Users/Matt/PhpstormProjects/barebones/system/database/drivers/mysqli/mysqli_driver.phpLine Number: 135
Backtrace:
File: /Users/Matt/PhpstormProjects/barebones/application/third_party/MX/Loader.php Line: 173 Function: _ci_load_library
File: /Users/Matt/PhpstormProjects/barebones/application/controllers/Migrate.php Line: 14 Function: library
File: /Users/Matt/PhpstormProjects/barebones/public_html/index.php Line: 313 Function: require_once
PHP Fatal error: Call to a member function query() on a non-object in /Users/Matt/PhpstormProjects/barebones/system/database/drivers/mysqli/mysqli_driver.php on line 221
Fatal error: Call to a member function query() on a non-object in /Users/Matt/PhpstormProjects/barebones/system/database/drivers/mysqli/mysqli_driver.php on line 221
A PHP Error was encountered
Severity: ErrorMessage: Call to a member function query() on a non-objectFilename: /Users/Matt/PhpstormProjects/barebones/system/database/drivers/mysqli/mysqli_driver.phpLine Number: 221
Backtrace:
Can anybody help me with this? So that I can run this through the terminal.
Thanks