Home >Backend Development >PHP Tutorial >Use laravel to generate sql with brackets, laravelsql_PHP tutorial
<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> ?)
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>
select [COD(mg/L)] from huaxue
Try
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]" ]