Php 如何使用原始查询laravel添加单引号而不是双引号?
以下是我的疑问Php 如何使用原始查询laravel添加单引号而不是双引号?,php,laravel,laravel-5,laravel-query-builder,Php,Laravel,Laravel 5,Laravel Query Builder,以下是我的疑问 select "column1", "desc", if r_id = P then Y else 'N' endif As is_selected from "other" where "rtype" = D_STATUS 下面是我的查询生成器函数 DB::table('other') ->select('r_id', 'description', DB::raw("if r_
select "column1", "desc", if r_id = P then Y else
'N' endif As is_selected from "other" where
"rtype" = D_STATUS
下面是我的查询生成器函数
DB::table('other')
->select('r_id', 'description', DB::raw("if r_id ='P' then 'Y' else 'N' endif As is_selected")) //Error
->where('rtype', '=', $strType )
->get();
这里我得到了错误
找不到“Y”列
我想在查询中的所有静态字符串值中添加单引号而不是双引号。我该怎么做呢?试试看:
你可以使用反冲
DB::table('other')
->select('r_id', 'description', DB::raw("if r_id ='P' then \"Y\" else \"N\" endif As is_selected")) //Error
->where('rtype', '=', $strType )
->get();
文档是否是,我只需在Y列和N列周围添加单引号。您能告诉我如何才能做到这一点吗@KamleshPaulNo backtick键不起作用@kamleshpaul我认为您的代码是正确的,因为错误是说
列“Y”未找到
表示在表中此列不存在我的查询工作正常。此查询在'Y'@KamleshPaul附近缺少一个引号
DB::table('other')
->select('r_id', 'description', DB::raw("if r_id ='P' then \"Y\" else \"N\" endif As is_selected")) //Error
->where('rtype', '=', $strType )
->get();