Search code examples
phpstringmigrationphinx

when phinx migrate, string in double quotes("") is not recognized correctly


enter image description here

I have migration using phinx, above picture is the data seed.
(I just boxed out some sections, sorry for it)

As you can see, there are blue color characters which are not recognized and I don't know why...
They are within double quotes " " and I think all kind of quotes (", ', `) match correctly
but when I do

$ php phinx migrate

the result turns to be like this:

enter image description here

Somehow those blue characters are recognized as variables instead of strings? Any guess for the possibilities will be appreciated. I'm using VSCode(don't think I have to say this but... yes)


Solution

  • When inside double quotes, PHP interprets $something as a variable, so in your migration code PHP tries to get the value for all those blue values in the picture.

    In order to get it to work, you need to either use single quotes and escape every single single quote inside the queries, or keep your double quotes and escape only the dollar signs (when applicable).

    <?php
    $a = "test";
    echo "this is a $a"; // this is a test <-- this is what's happening to you
    echo 'this is a \'$a\''; // this is a '$a' <-- one option
    echo "this is a \$a"; // this is a $a <-- another opcion
    

    So it would look something like this:

    $this->execute("INSERT INTO table (email, password) VALUES ('[email protected]', '\$2y\$10\$aerjgap2341234ommubi1234123');