Laravel: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
(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...")
 
mNo edit summary
Line 1: Line 1:
[https://laravel.com/ Laravel - The PHP Framework For Web Artisans] (繁體中文文件: [https://laravel.tw/ Laravel - 為網頁藝術家創造的 PHP 框架])


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

Revision as of 11:14, 29 August 2019

Laravel - The PHP Framework For Web Artisans (繁體中文文件: Laravel - 為網頁藝術家創造的 PHP 框架)

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