私はさまざまな方法を試しましたが、どれもうまくいかないようです。MySQLコンソールでコマンドを試すと正常に機能しますが、このPHPスクリプトでコマンドを試すと、空の文字列が返されます。
$search = $mysqli->prepare("SELECT item_path FROM items WHERE item_title = ?");
while (array_key_exists($i, $parts)) {
// An array that contains (word1, word2, word3)
$data = $parts[$i];
// Wraps data in "" for mysqli query
$data = "\"" . $data . "\"";
// Binding here still doesn't work
$search->bind_param("s", $data);
// This should execute the above prepare and give me the data
// from the way I think it work's this execute() should use the updated $data
$search->execute();
$search->bind_result($img_path);
$search->fetch();
// This returns an empty string
echo $img_path;
echo "<img src= \"", $img_path, "\" >";
$i++;
}
MySQLコンソールに移動して実行すると、次のようになります。
SELECT item_path FROM items WHERE item_title = "word1"
期待しているitem_pathを取得しましたが、何らかの理由でスクリプトが空の文字列を返します。
助けてくれてありがとう(もしそうなら)!
編集:
// Wraps data in "" for mysqli query
$data2 = "\"" . $data . "\"";
// Binding here still doesn't work even after changing the var
$search->bind_param("s", $data2);
別の変数へのバインドを変更するのに疲れましたが、それでも空の文字列を取得します。それが原因でデータが正しくラップされていないのか、それとも別の理由があるのかわかりません。私はこのようなことが起こることを探していましたが、何も思いつきませんでした。