1
我使用Laravel的Illuminate數據庫管理器,除了現在使用LIKE
操作以外,其工作非常好。Elequent /照亮Laravel數據庫LIKE操作不起作用
我已經試過那些選項,但一無所獲:
function initConnection()
{
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => $this->config['host'],
'database' => $this->config['database-name'],
'username' => $this->config['username'],
'password' => $this->config['password'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
}
和初始化後,我想:
function searchByName($word)
{
return Capsule::table($table)
->get()
->where('name', 'LIKE', '%'.$word.'%')
->first();
}
echo searchByName('John');
我也試過這個選項:
Capsule::table('table_name')
->select('SELECT * FROM table_name WHERE table_name.name LIKE "%John%"');
這也失敗了。
我找不到在Laravel中使用所有操作的文檔。