Home > Backend Development > PHP Tutorial > Use laravel to generate sql with brackets, laravelsql_PHP tutorial

Use laravel to generate sql with brackets, laravelsql_PHP tutorial

WBOY
Release: 2016-07-13 10:21:03
Original
1241 people have browsed it

Use laravel to generate sql with brackets, laravelsql

laravel query builder use where case ​ I want to sql like that : ​
<span>select</span> <span>*</span> <span>from</span> `wxm_ticket` <span>where</span> `wxm_ticket`.`deleted_at` <span>is</span> <span>null</span> <span>and</span> `<span>user_id</span>` <span>=</span> ? <span>and</span> `sell_status` <span>=</span> ? <span>and</span> (`stop_sell` <span>is</span> <span>null</span> <span>or</span> `stop_sell` <span>>=</span> ?)
Copy after login

​ php code: ​
<span>$query</span> = TicketModel::user(<span>$admin_id</span>)->sellStatus(1)->where(<span>function</span>(<span>$query</span><span>){
</span><span>$query</span>->orWhereNull('stop_sell')->orWhere('stop_sell', '>=', \Carbon\Carbon::<span>now());
});;</span>
Copy after login

The SQL statement field name is in English and has English brackets. Is there an error in the query?

select [COD(mg/L)] from huaxue
Try

When creating a table in SQL2000 at user level, etc., brackets are automatically added

user, level are considered system reserved keywords by sqlserver. Direct use may cause ambiguity in some places. Adding square brackets does not affect any use, but brackets should also be added in statements. In the code, field names do not have brackets. Standard SQL statements should also be bracketed. For example:
SELECT [F1], [F2], [F3] FROM [MyTable] WHERE [F1] = @f1 AND [F2] = @f2

In C# code, such as DataTable, DataReader Inside, when you need to use field names or table names, you do not need to use parentheses.

For example, a DataTable tb;

tb.Rows[0][ "F1" ] is enough, but tb.Rows[0][ "[F1]" ]

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/863581.htmlTechArticleUse laravel to generate sql with brackets, laravelsql laravel query builder use where caseI want to sql like that : select * from `wxm_ticket` where `wxm_ticket`.`deleted_at` is null a...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template