gpt4 book ai didi

php - undefined variable : error while running the raw sql query

转载 作者:行者123 更新时间:2023-11-29 02:51:20 24 4
gpt4 key购买 nike

我正在尝试使用 laravel 的 DB::statement() 使用原始 SQL 语句插入数据,但问题是当我在播种机中运行它时,控制台认为密码是可变的而不是字符串

这是代码

DB::statement("INSERT INTO `users` (`id`, `email`, `password`, `permissions`, `activated`, `activation_code`, `activated_at`, `last_login`, `persist_code`, `reset_password_code`, `first_name`, `last_name`, `created_at`, `updated_at`)
VALUES
(13, '1@1.com', '$2y$10$FGKgaSVG6ZQS19mg9c2nMutVjQuIL0OMYsXcB4ZkE5dntL72Wq8N6', NULL, 1, NULL, NULL, NULL, NULL, NULL, 'Edwin', 'Lugo', '2016-01-12 23:49:01', '2016-01-12 23:49:01'),
(14, '2@1.com', '$2y$10$xIruVm4ju60hIOahIjaP4ewZbVYO69Xwr4IOFw7D5H/74wXNQ8RlO', NULL, 1, NULL, NULL, NULL, NULL, NULL, 'Max', 'Bonilla ', '2016-01-12 23:50:21', '2016-01-12 23:50:21'),
(15, '3@1.COM', '$2y$10$tmhzXsF5jlTwWDXRObzHLOAmZzDcMDK0GdbImUnUYtfIn.WWaIj8a', NULL, 1, NULL, NULL, NULL, NULL, NULL, 'Denny', 'Tran ', '2016-01-12 23:51:42', '2016-01-12 23:51:42')");

结果是

Console error

PS:我使用的是 Laravel 4

最佳答案

PHP 处理双引号中的变量。由于 $ 和尾随文本,您的密码字符串被读取为变量($2 不会导致问题,因为它在 PHP 中是无效的变量名称,因此它不会'甚至不要尝试处理它)。

问题的简单演示:https://3v4l.org/mM211
更正的简单演示:https://3v4l.org/YWKtC

您的代码应该是什么样子:

'INSERT INTO `users` (`id`, `email`, `password`, `permissions`, `activated`, `activation_code`, `activated_at`, `last_login`, `persist_code`, `reset_password_code`, `first_name`, `last_name`, `created_at`, `updated_at`)
VALUES
(13, "1@1.com", "$2y$10$FGKgaSVG6ZQS19mg9c2nMutVjQuIL0OMYsXcB4ZkE5dntL72Wq8N6", NULL, 1, NULL, NULL, NULL, NULL, NULL, "Edwin", "Lugo", "2016-01-12 23:49:01", "2016-01-12 23:49:01"),
(14, "2@1.com", "$2y$10$xIruVm4ju60hIOahIjaP4ewZbVYO69Xwr4IOFw7D5H/74wXNQ8RlO", NULL, 1, NULL, NULL, NULL, NULL, NULL, "Max", "Bonilla ", "2016-01-12 23:50:21", "2016-01-12 23:50:21"),
(15, "3@1.COM", "$2y$10$tmhzXsF5jlTwWDXRObzHLOAmZzDcMDK0GdbImUnUYtfIn.WWaIj8a", NULL, 1, NULL, NULL, NULL, NULL, NULL, "Denny", "Tran ", "2016-01-12 23:51:42", "2016-01-12 23:51:42")'

关于php - undefined variable : error while running the raw sql query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com