PHP
1 2$sql = "SELECT * FROM hotels JOIN hotels_tags ON hotels.hotel_id = hotels_tags.hotel_id AND hotels.country_code = hotels_tags.country_code JOIN tags ON hotels_tags.tags_id = tags.tags_id WHERE (hotels.hotel_id, hotels.country_code) in (SELECT hotel_id, country_code from areas where area like ?) AND "; 3$word = "'おはよう'"; 4$sql .= "tags.tag =" + $word;
result
1string(313) "SELECT * FROM hotels JOIN hotels_tags ON hotels.hotel_id = hotels_tags.hotel_id AND hotels.country_code = hotels_tags.country_code 2 JOIN tags ON hotels_tags.tags_id = tags.tags_id WHERE (hotels.hotel_id, hotels.country_code) in (SELECT hotel_id, country_code from areas where area like ?) AND 0"
のように変数を用いるとエラーになります。
しかし
$sql = "SELECT * FROM hotels JOIN hotels_tags ON hotels.hotel_id = hotels_tags.hotel_id AND hotels.country_code = hotels_tags.country_code JOIN tags ON hotels_tags.tags_id = tags.tags_id WHERE (hotels.hotel_id, hotels.country_code) in (SELECT hotel_id, country_code from areas where area like ?) AND "; $sql .= "tags.tag =";
のようにするとエラーになりません。
result
1string(322) "SELECT * FROM hotels JOIN hotels_tags ON hotels.hotel_id = hotels_tags.hotel_id AND hotels.country_code = hotels_tags.country_code 2 JOIN tags ON hotels_tags.tags_id = tags.tags_id WHERE (hotels.hotel_id, hotels.country_code) in (SELECT hotel_id, country_code from areas where area like ?) AND tags.tag ="
どのように解決すれば良いですか。
回答2件
あなたの回答
tips
プレビュー