未定义的变量:运行原始sql查询时出错

时间:2016-02-10 06:15:21

标签: php mysql laravel-4

我正在尝试使用laravel的faces = faceCascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags = cv2.cv.CV_HAAR_SCALE_IMAGE ) 使用原始SQL语句插入数据,但问题是当我在播种器中运行它时控制台认为密码是可变的而不是字符串

这是代码

DB::statement()

导致

Console error

PS:我正在使用Laravel 4

1 个答案:

答案 0 :(得分:1)

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")'