0
といくつかのトラブルを持って、私が実行しようとしています:もちろんだからLaravel前記
$table = 'russian_names';
$nameType = 1;
$options = array(1, 2, 6);
$names = DB::table($table)
->where('name_type', $nameType)
->whereIn('options', $options)
->get();
を、私はrussian_names
の行を持っている:
id: 1
name: Vito
name_type: 1
options: 1,2,3,6
short_description: Short description for Vito.
description: Full description for Vito.
しかし、私は常に空の配列を取得します。 $options
の各要素を文字列に変換しようとしましたが、結果はありません。また、私はwhereIn
せずにこのクエリを実行しようとし、それが動作します。また、私はexucute
select * from `russian_names` where `name_type` = 1 and `options` in (1, 2, 6)
phpmyadminでそれは完全に動作します。私が行方不明のものはありますか?
UPD:私は、このログを示すmysqlのクエリログ:
select * from `russian_names` where `name_type` = ?
は細かい動作してくれた結果の配列を示すため
select * from `russian_names` where `name_type` = ? and `options` in (?, ?, ?)
は、normaly見えます。
残念ながら、MySQLの新しいJSON 'データ型まだ 'IN'クエリをサポートしていません。あなたがPostgresにいたなら、JSONカラムでこれを行うことができます。 – ceejayoz
ああ私はそれを得た。私は誤って '%1% 'のようなものが見つかると思っていましたが、' options = 1'を検索して空の配列があるのです。どうもありがとう! –
@VitoGravanoええ、 'WHERE options IN(1,2,6)'は 'WHERE(options = 1 OR options = 2 OR options = 6)'の略です。 – ceejayoz