表达不够清晰,
同链接跨库查询,
原生sql是通过
SELECT
(CASE WHEN xxx = '123' THEN 321 ELSE 123)
FROM (
SELECT FROM hk.user WHERE active = 1 UNION ALL
SELECT FROM ma.user WHERE active = 1 UNION ALL
SELECT * FROM bl.user WHERE active = 1
) as b ORDER BY addDate DESC
其实我只是需要执行原生的SQL。
默认的laravel DB没有原生SQL执行方法,
查看laravel手册,发现Facades\DB类有执行原生SQL的方法,
所以才使用Facades\DB,但是替换后一直出错,提示RuntimeException: A facade root has not been set.
DB::select('select * from users where id = :id', ['id' => 1]);
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);
DB::update('update users set votes = 100 where name = ?', ['John']);
DB::delete('delete from users');
Illuminate\Support\Facades\DB会报A facade root has not been set.然后使用Illuminate\Database\Capsule\Manager 可以执行,但是没有代码提示。请问如何 用Illuminate\Support\Facades\DB不报错,谢谢
为啥说不能通过support\Db 做夸库查询?
表达不够清晰,
同链接跨库查询,
原生sql是通过
SELECT
(CASE WHEN xxx = '123' THEN 321 ELSE 123)
FROM (
SELECT FROM hk.user WHERE active = 1 UNION ALL
SELECT FROM ma.user WHERE active = 1 UNION ALL
SELECT * FROM bl.user WHERE active = 1
) as b ORDER BY addDate DESC
抽象下就好像上面的,甚至还有更复杂的
跨库联合查询只能单独一个库查询出来
其实我只是需要执行原生的SQL。
默认的laravel DB没有原生SQL执行方法,
查看laravel手册,发现Facades\DB类有执行原生SQL的方法,
所以才使用Facades\DB,但是替换后一直出错,提示RuntimeException: A facade root has not been set.
我遇到和你同样的问题,请问最后如何解决的?
laravel 支持原生sql,同样webman默认用的laravel的数据库类,也支持。类似这样的用法
可做夸库 连表复杂查询
感谢回复。
试过了,直接没返回
趴了下代码,LARVEL是需要使用 Illuminate\Support\Facades\DB 才能运行DB::select(xxx)
但是webman是使用了Illuminate\Database\Capsule\Manager
Illuminate\Database\Capsule\Manager这个是没有DB::select 的方法
我试过了,可以
@1:我刚抽出来试了可以....可是我之前测试一直是没有报错,也没有返回......anyway 感谢!
Illuminate\Support\Facades\DB会报A facade root has not been set.然后使用Illuminate\Database\Capsule\Manager 可以执行,但是没有代码提示。请问如何 用Illuminate\Support\Facades\DB不报错,谢谢