1

Phinx is nice tool to database migration and it is working fine with terminal creating tables and seeding data into it by commands, but I want to see some output on the browser from this code before inserting into the tables can anyone help me out how to put some var_dumps in in and see output on terminal or in the browser somehow?

Example Code:

public function up()
{

    $userLinks = $this->fetchAll('SELECT * FROM user_links');
    var_dump($userLinks);

    foreach ($userLinks as $userLink) {
        $actionPlugin = ucfirst($userLink['action']);
        $actionParams = array();
        $actionParams['UserID'] = $userLink['userID'];

        if (isset($userLink['userSurveyID'])) {
            $actionParams['UserSurveyID'] = $userLink['userSurveyID'];
        }
        $jsonParamString = json_encode($actionParams);

        $this->execute("
            INSERT INTO `token_links` (`linkID`, `token`, `actionPlugin`, `actionParams`) VALUES
            ({$userLink['userLinkID']}, '{$userLink['token']}', '$actionPlugin', '$jsonParamString');
            ");
    }


}
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
zarpio
  • 10,380
  • 8
  • 58
  • 71
  • If you run command `phinx migrate -e development` you will see messages from standard output, so you can add `var_dump`, `echo` or even `print` and add die before execution of query – alexander.polomodov Mar 12 '16 at 21:49
  • Great is is being print on the terminal :) But how to show these output on browser? – zarpio Mar 12 '16 at 22:15
  • How do you run this migration from browser? – alexander.polomodov Mar 12 '16 at 22:16
  • No I don't want to run this migration from browser just want output using this AbstractMigration class, it is impossible to see thousand's of records from loop in the terminal. – zarpio Mar 12 '16 at 22:18
  • You can add some logging which would be accessible by webserver – alexander.polomodov Mar 12 '16 at 22:23
  • Thank you @alexander.polomodov for giving me some tips. Can you please write your detailed answer so I can approve and it would be also great for newbies like me. Please suggest nice logging tool compatible wtih phinx – zarpio Mar 12 '16 at 22:27
  • Phinx is not specific with logging. You can use any logging system. For example we prefer `logstash` because it nicely works with `kibana`:) But you can use standard `error_log` php function or just write to file inside one of your webserver directory. – alexander.polomodov Mar 12 '16 at 22:35

1 Answers1

4

When phinx run its migration (e.g. with command phinx migrate -e development)all output generated with commands like echo, var_dump, print go straight to standard output.

  • So if you run this command from console you will see debug message.
  • But if you want to see this message from browser you should use some logging system.

My personal preference to use logstash, but you can use standard php function error_log or even write to file which is accessible by your webserver.

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46