Editing
Laravel
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[https://laravel.com/ Laravel - The PHP Framework For Web Artisans] (繁體中文文件: [https://laravel.tw/ Laravel - 為網頁藝術家創造的 PHP 框架]) == SQL 查詢語法 Where 變數部分使用問號 == {{exclaim}} "Raw statements will be injected into the query as strings, so you should be extremely careful to not create SQL injection vulnerabilities."<ref>[https://laravel.com/docs/5.6/queries#raw-expressions Raw Expressions]</ref> 原始 SQL 查詢語法 <pre> SELECT `content` FROM `articles` WHERE `content` LIKE "%$search_keyword%" </pre> 使用 Laravel {{kbd | key=whereRaw}} 或 {{kbd | key=orWhereRaw}},範例代碼 <pre> $query = DB::table("articles") ->select("content") ->whereRaw("content LIKE ? ", ["%$search_keyword%"]) </pre> 另一種 Laravel 寫法 <pre> $query = DB::table("articles") ->select("content") ->where("content", "LIKE", "%$search_keyword%") </pre> 相關資料 * [https://stackoverflow.com/questions/25244317/laravel-concat-in-query-where-condition sql - Laravel concat in query (where condition) - Stack Overflow] * [https://laravel.com/docs/5.6/queries#introduction Database: Query Builder - Laravel - The PHP Framework For Web Artisans] "The Laravel query builder uses PDO parameter binding to protect your application against SQL injection attacks. There is no need to clean strings being passed as bindings." * [https://laracasts.com/discuss/channels/eloquent/how-do-you-parameterize-whereraw-in-the-query-builder How do you parameterize whereRaw() in the query builder?] == References == <references /> [[Category:PHP]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Exclaim
(
edit
)
Template:Kbd
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information