php - 如何用mysql转义引号内的反斜杠

标签 php mysql laravel laravel-5

我正在使用 Laravel 迁移来创建/管理我所有的数据库脚本,并且我有一个用于创建触发器的迁移。

在这里

DB::unprepared(
    'create trigger update_points_aft_insert
        after insert on votes
        for each row
        begin
            declare u_id integer;
            if NEW.votable_type = "App\\Comment" then
                set u_id = (select user_id from comments where id = NEW.votable_id);
                update users set points=points+NEW.vote where id = u_id;
            end if;
    end;'
);

问题是当我运行 show triggers; 时我得到:

*************************** 1. row ***************************
         Trigger: update_points_aft_insert
           Event: INSERT
           Table: votes
       Statement: begin
                declare u_id integer;
                if NEW.votable_type = "AppComment" then
                    set u_id = (select user_id from comments where id = NEW.votable_id);
                    update users set points=points+NEW.vote where id = u_id;
                end if;
            end
          Timing: AFTER
         Created: NULL
        sql_mode: NO_ENGINE_SUBSTITUTION
         Definer: root@localhost

字符集客户端:utf8 collat​​ion_connection: utf8_unicode_ci 数据库整理:latin1_swedish_ci

可以看到,mysql读取的是if NEW.votable_type = "AppComment" then而不是我想要的:if NEW.votable_type = "App\Comment" then ... 任何人都知道如何告诉 mysql 读取反斜杠?

编辑:有效的方法是使用三个反斜杠

最佳答案

要考虑反斜杠,您应该将其加倍。因此,“App\\\\Comment”应该给你“App\Comment”

关于php - 如何用mysql转义引号内的反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35894979/

相关文章:

sql - WHERE 语句中无法识别列别名

php - Laravel 5.6 在我的 Blade View 中显示 svg 图标不起作用

php - Apache 中的 Laravel 获取 header 值

php - 使用复选框从数据库中提取电子邮件地址(PHP、MYSQL)

mysql - MySQL SQL 语法错误

php - MySQL查询错误

php - 不关闭 mysql 连接是否有任何可能的负面影响

php - 调整图像的宽度和高度(模型 Blade )Laravel

php - 逻辑编程帮助

php - Laravel:对多个值进行多对多过滤