phinx 迁移时,双引号 ("") 中的字符串无法正确识别
when phinx migrate, string in double quotes("") is not recognized correctly
我用phinx迁移,上图是数据种子
(我只是删掉了一些部分,不好意思)
如你所见,有蓝色的字符是
无法识别,我不知道为什么...
它们在双引号 " " 内,我认为所有类型的引号 (", ', `) 都正确匹配
但是当我这样做时
$phpphinx 迁移
结果变成这样:
不知何故,那些蓝色字符被识别为变量而不是字符串?对可能性的任何猜测将不胜感激。我正在使用 VSCode(我想我不必这么说但是......是的)
当在双引号内时,PHP 将 $something
解释为一个变量,因此在您的迁移代码中 PHP 尝试获取图片中所有这些蓝色值的值。
为了使其正常工作,您需要使用单引号并转义查询中的每个单引号,或者保留双引号并仅转义美元符号(如果适用)。
<?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
所以它看起来像这样:
$this->execute("INSERT INTO table (email, password) VALUES ('email@test.com', '$2y$10$aerjgap2341234ommubi1234123');
我用phinx迁移,上图是数据种子
(我只是删掉了一些部分,不好意思)
如你所见,有蓝色的字符是
无法识别,我不知道为什么...
它们在双引号 " " 内,我认为所有类型的引号 (", ', `) 都正确匹配
但是当我这样做时
$phpphinx 迁移
结果变成这样:
不知何故,那些蓝色字符被识别为变量而不是字符串?对可能性的任何猜测将不胜感激。我正在使用 VSCode(我想我不必这么说但是......是的)
当在双引号内时,PHP 将 $something
解释为一个变量,因此在您的迁移代码中 PHP 尝试获取图片中所有这些蓝色值的值。
为了使其正常工作,您需要使用单引号并转义查询中的每个单引号,或者保留双引号并仅转义美元符号(如果适用)。
<?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
所以它看起来像这样:
$this->execute("INSERT INTO table (email, password) VALUES ('email@test.com', '$2y$10$aerjgap2341234ommubi1234123');