Use laravel to generate an SQL statement with parentheses.

Source: Internet
Author: User

Use laravel to generate an SQL statement with parentheses.
Laravel query builder use where case I want to SQL like that:

select * from `wxm_ticket` where `wxm_ticket`.`deleted_at` is null and `user_id` = ? and `sell_status` = ? and (`stop_sell` is null or `stop_sell` >= ?)

 

Php code:
$query = TicketModel::user($admin_id)->sellStatus(1)->where(function($query){$query->orWhereNull('stop_sell')->orWhere('stop_sell', '>=', \Carbon\Carbon::now());});;

 


The SQL statement field name is in English and contains English brackets. What is the query error?

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

Create user level and other automatic brackets in SQL2000

User and level are considered by sqlserver as keywords reserved by the system. Using them directly may cause ambiguity in some places. Adding brackets does not affect any use. However, brackets should also be added in the statement. In the code, the field name is not in brackets. Brackets should also be added to standard SQL statements. For example:
SELECT [F1], [F2], [F3] FROM [MyTable] WHERE [F1] = @ f1 AND [F2] = @ f2

In C # code, such as DataTable and DataReader, brackets are not required when you need to use the field name or table name.

For example, a DataTable tb;

Tb. Rows [0] ["F1"], instead of tb. Rows [0] ["[F1]"]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.