Laravel

From LemonWiki共筆
Revision as of 11:11, 29 August 2019 by Planetoid (talk | contribs) (Created page with " == SQL 查詢語法 Where 變數部分使用問號 == {{exclaim}} "Raw statements will be injected into the query as strings, so you should be extremely careful to not creat...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

SQL 查詢語法 Where 變數部分使用問號

Icon_exclaim.gif "Raw statements will be injected into the query as strings, so you should be extremely careful to not create SQL injection vulnerabilities."[1]

原始 SQL 查詢語法

SELECT `content`
FROM `articles`
WHERE `content` LIKE "%$search_keyword%"

使用 Laravel whereRaworWhereRaw,範例代碼

$query = DB::table("articles")
        ->select("content")
        ->whereRaw("content LIKE ? ", ['%' . $search_keyword . '%'])

另一種 Laravel 寫法

$query = DB::table("articles")
        ->select("content")
        ->where("content", "LIKE", '%' . $search_keyword . '%')

相關資料

References