Skip to content

Instantly share code, notes, and snippets.

@jmny
Last active December 14, 2023 04:44
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmny/c957de6984c9d939c059 to your computer and use it in GitHub Desktop.
Save jmny/c957de6984c9d939c059 to your computer and use it in GitHub Desktop.
phinx outside cli
// see also https://github.com/robmorgan/phinx/issues/364
$phinxApp = new \Phinx\Console\PhinxApplication();
$phinxTextWrapper = new \Phinx\Wrapper\TextWrapper($phinxApp);
$phinxTextWrapper->setOption('configuration', '/path/to/phinx.yml');
$phinxTextWrapper->setOption('parser', 'YAML');
$phinxTextWrapper->setOption('environment', 'development');
$log = $phinxTextWrapper->getMigrate();
@blakethepatton
Copy link

Oh my goodness, something that actually worked! THANK YOU!

Also, a trap for beginners, don't forget to autoload composer:

require __DIR__ . '/vendor/autoload.php';

@tflight
Copy link

tflight commented Aug 18, 2016

+1

@rafaelbeckel
Copy link

+1
Thanks so much for this! It should be in the official docs!

@ebayaccountvv
Copy link

Hi
When I run above commands it works but nothing happens in the database. Please see my output

C:/xampp/htdocsstring(266) "Phinx by CakePHP - https://phinx.org. 0.10.6 using config file .\vendor\bin\phinx.php using config parser php using migration paths using seed paths using environment development using adapter mysql using database production_db All Done. Took 0.0841s "

Also i am putting my code here

require DIR . '/vendor/autoload.php';

$phinxApp = new \Phinx\Console\PhinxApplication();

$phinxTextWrapper = new \Phinx\Wrapper\TextWrapper($phinxApp);
$phinxTextWrapper->setOption('configuration', 'C:/xampp/htdocs/CI_PROJECT/phinix/vendor/bin/phinx.php');
$phinxTextWrapper->setOption('parser', 'php');
$phinxTextWrapper->setOption('environment', 'development');

$log = $phinxTextWrapper->getMigrate('development','-t');
var_dump($log);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment