本文介紹了如何將整理添加到 Laravel 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我需要像這樣運(yùn)行具有 collat??e utf8_bin
的查詢:
I need to run a query having collate utf8_bin
like so:
SELECT * FROM `table` WHERE `field`='value' collate utf8_bin;
這僅適用于管理腳本,我不想更新表字符集本身,僅適用于特定查詢.
This is strictly for an admin script and I don't want to update the table charset itself, just for the particular query.
我可以使用 Eloquent ORM 來執(zhí)行此操作還是需要寫出此查詢?
Can I do this using the Eloquent ORM or do I need to write this query out?
推薦答案
既然可以配置MySQL驅(qū)動使用一個:
Since you can configure MySQL driver to use one:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
您可以為您的特定查詢創(chuàng)建不同的連接:
You can create a different connection for your particular query:
'mysql-collation' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => '<your collation>',
'prefix' => '',
),
并在您的查詢中使用該連接:
And use that connection on your query:
$users = DB::connection('mysql-collation')->select(...);
在模型上,您可能可以通過這種方式設(shè)置連接:
On a Model, you probably will be able to set a connection this way:
$posts = new Word;
$posts->setConnection('mysql-collation');
$posts->where(...);
這篇關(guān)于如何將整理添加到 Laravel 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!