LoginSignup
0
0

CakePHP5 WEHE句でのbind

Posted at

WHERE id NOT IN(SELECT id FROM xxx WHERE code=?) こんなクエリを作りたい

https://book.cakephp.org/5/ja/orm/database-basics.html#id15
ステートメントを準備する
あなたは execute() か prepare() でステートメントオブジェクトを生成できます。 execute() メソッドは引き継いだ値をバインドしたステートメントを返します。 それに対して prepare()
は不完全なステートメントを返します。

ConnectionManager::get('default') して、prepare して bind して... とあれこれ試してみたもののシンプルに書けなかった。

シンプルな方法

$rows = $this->Xxx->find('all')
->where('Xxx.id NOT IN (SELECT id FROM xxx WHERE code = :code)')
->bind(':code',$code,'integer');

プレースホルダ「?」として、bind にプレースホルダを指定しなくてもいい方法を探ったけど断念。。

誰か教えて。。

直感的にこう書きたい。。

->where('Xxx.id NOT IN (SELECT id FROM xxx WHERE code = ? AND code2 = ?)')
->bind([$code,$code2],['integer','integer']);
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0