以下のサイトを参考にpdoでwhere inを使おうとしているのですが、うまくいきません。
上記サイトを参考に現在コードはこのように書いています。
php
1 $postedType = $this->getPostedType(); 2 $postedWords = $this->getPostedWords(); 3 $inClause = substr(str_repeat(',?', count($postedWords)), 1); 4 5 try { 6 $pdo = new PDO($this->dsn, $this->username, $this->password); 7 $stmt = $pdo->prepare(sptinrf('SELECT * FROM WordPack WHERE type = ? and word not in (%s) limit 10', $inClause)); 8 $stmt->execute(array_merge( 9 array($postedType), 10 $postedWords 11 )); 12 $results = $stmt->fetchAll(); 13 return $results; 14 15 } catch (PDOException $e) { 16 return null; 17 }
ログを出しつつ確認したところ、「$pdo->prepare」の行の下を処理が通っていませんでした。
ちなみに$postedTypeと$postedWordsに入っている値は以下のようになっています。
$postedType
1
$postedWords
(
[0] => aaa
[1] => bbb
[2] => ccc
[3] => ddd
[4] => eee
[5] => fff
[6] => ggg
[7] => hhh
[8] => iii
[9] => jjj
[10] => kkk
[11] => lll
)
どこを修正すればいいかが分からず詰まってしまっています。
どうすればwhere inを使ってDBから値を引っ張ってこれるようになるでしょうか?
どなたか分かる方がいれば教えていただきたいです。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/20 06:27
2018/12/20 06:29
退会済みユーザー
2018/12/20 07:00
2018/12/20 07:07