Laravel Eloquent ORM - 复杂的 where 查询
Laravel Eloquent ORM - Complex where queries
我有以下查询:
DB::select("SELECT * FROM mod_dns_records WHERE (scheduled = 'N' AND scheduleTime = 0 AND domainId = {$id}) OR (deleteRow = 'Y' AND domainId = {$id})");
但是,这对于 SQL 注入来说并不安全。谁能帮我确保它安全,或者告诉我如何用 ORM 重建它。
谢谢!
这将是您的查询
$result = DB::table('mod_dns_records')
->where('scheduled', 'N')
->where('scheduleTime', 0)
->where('domainId', $id)
->orWhere('deleteRow', 'Y')
->where('domainId', $id)
->get();
不过我注意到它可以稍微优化一下,因为 domainId
条件在两个组中都存在:
$result = DB::table('mod_dns_records')
->where('domainId', $id)
->where(function($q){
$q->where('scheduled', 'N');
$q->where('scheduleTime', 0);
$q->orWhere('deleteRow', 'Y');
})
->get();
我有以下查询:
DB::select("SELECT * FROM mod_dns_records WHERE (scheduled = 'N' AND scheduleTime = 0 AND domainId = {$id}) OR (deleteRow = 'Y' AND domainId = {$id})");
但是,这对于 SQL 注入来说并不安全。谁能帮我确保它安全,或者告诉我如何用 ORM 重建它。
谢谢!
这将是您的查询
$result = DB::table('mod_dns_records')
->where('scheduled', 'N')
->where('scheduleTime', 0)
->where('domainId', $id)
->orWhere('deleteRow', 'Y')
->where('domainId', $id)
->get();
不过我注意到它可以稍微优化一下,因为 domainId
条件在两个组中都存在:
$result = DB::table('mod_dns_records')
->where('domainId', $id)
->where(function($q){
$q->where('scheduled', 'N');
$q->where('scheduleTime', 0);
$q->orWhere('deleteRow', 'Y');
})
->get();