Home > php教程 > php手册 > 使用laravel 生成 带括号的sql,laravelsql

使用laravel 生成 带括号的sql,laravelsql

WBOY
Release: 2016-06-13 09:27:17
Original
1318 people have browsed it

使用laravel 生成 带括号的sql,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

 

SQL语句字段名是英文的并且带英文括号,查询出错?

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

在SQL2000建立表user level等自动加括号

user, level 被sqlserver认为是系统保留关键字,直接使用有可能在某些地方造成歧义。加上了中括号,不影响任何使用,但是在语句里,也应当加上括号,在代码里面,字段名是没有括号的。标准SQL语句也应当加上括号。比如:
SELECT [F1], [F2], [F3] FROM [MyTable] WHERE [F1] = @f1 AND [F2] = @f2

在C#代码里,比如DataTable,DataReader里面,需要使用字段名或者表名的时候,不需要使用括号。

比如一个DataTable tb;

tb.Rows[0][ "F1" ] 就可以了,而不需要 tb.Rows[0][ "[F1]" ]
 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template