How to add collate to laravel query(如何将整理添加到 Laravel 查询)
问题描述
我需要像这样运行具有 collate 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 来执行此操作还是需要写出此查询?
Can I do this using the Eloquent ORM or do I need to write this query out?
推荐答案
既然可以配置MySQL驱动使用一个:
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' => '',
),
您可以为您的特定查询创建不同的连接:
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(...);
在模型上,您可能可以通过这种方式设置连接:
On a Model, you probably will be able to set a connection this way:
$posts = new Word;
$posts->setConnection('mysql-collation');
$posts->where(...);
这篇关于如何将整理添加到 Laravel 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将整理添加到 Laravel 查询


基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01