![]() |
Database Migrations from the Terminal - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Database Migrations from the Terminal (/showthread.php?tid=1672) |
Database Migrations from the Terminal - mdixon18 - 03-31-2015 Hello Guys, I'm managing Migrations in my Codeigniter project. Here is my migration class: PHP Code: class Migrate extends CI_Controller 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 Can anybody help me with this? So that I can run this through the terminal. Thanks RE: Database Migrations from the Terminal - gadelat - 03-31-2015 It looks problem is in your hmvc implementation. Try to rename folder third_party/MX and run it via CLI again. RE: Database Migrations from the Terminal - mdixon18 - 03-31-2015 The spelling and capitalisation is correct. But I still have this problem. RE: Database Migrations from the Terminal - CroNiX - 03-31-2015 Are you relying on any $_SERVER variables in any of your code? Like to detect and set the environment? If so, those won't be set in a CLI request since it doesn't go through the web server. RE: Database Migrations from the Terminal - mdixon18 - 03-31-2015 That looks like it'll be the likely cause but in my code I'm saying that if the server variable is not set then it will automatically be development so surely that would be fine? RE: Database Migrations from the Terminal - CroNiX - 03-31-2015 The error referenced is where it's instantiating the db class using the supplied db credentials in line 135. I know I've seen people using $_SERVER variables to define environments, so thought I'd ask as they won't work with CLI. Quote: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 Are you using 127.0.0.1 as the db host, or "localhost"? If localhost, try switching to the local IP. RE: Database Migrations from the Terminal - mdixon18 - 04-01-2015 Away back on Thursday will let you know RE: Database Migrations from the Terminal - mwhitney - 04-01-2015 When using the MX Loader you usually need to extend MX_Controller (or some other controller which extends MX_Controller) instead of CI_Controller. Otherwise, libraries which are expected to be loaded onto $this may not be found. |