• 締切済み

php mysqlのクエリでエラー

「←追加」と追加したのですが、Warning: Invalid argument supplied for foreach()とエラーがでました。 調べたり、試行錯誤してみましたがダメでした。 何が間違っているのでしょうか? try{ $dbh = new PDO($dsn, $user, $password); print('接続に成功しました。<br>'); $dbh->query('SET NAMES utf8'); $sql = ('SELECT song.number, song.song_title, artist.artist, ka2.artist as artist_2, ka3.artist as artist_3, ka4.artist as artist_4, ka5.artist as artist_5, ka6.artist as artist_6, ka7.artist as artist_7, ka8.artist as artist_8, ka9.artist as artist_9, ka10.artist as artist_10, ka11.artist as artist_11, ka12.artist as artist_12, sakushi.sakushi, ss2.sakushi as sakushi_2, ss3.sakushi as sakushi_3, ss4.sakushi as sakushi_4, sakkyoku.sakkyoku, sk2.sakkyoku as sakkyoku_2, sk3.sakkyoku as sakkyoku_3, sk4.sakkyoku as sakkyoku_4, hennkyoku.hennkyoku, hk2.hennkyoku as hennkyoku_2, hk3.hennkyoku as hennkyoku_3, hk4.hennkyoku as hennkyoku_4, genre, gr2.genre as genre_2,←追加 tie_up, part FROM (((((((((((((((((((((((((((( song LEFT JOIN artist ON song.artist_1 = artist.artist_ID) LEFT JOIN artist ka2 ON song.artist_2 = ka2.artist_ID) LEFT JOIN artist ka3 ON song.artist_3 = ka3.artist_ID) LEFT JOIN artist ka4 ON song.artist_4 = ka4.artist_ID) LEFT JOIN artist ka5 ON song.artist_5 = ka5.artist_ID) LEFT JOIN artist ka6 ON song.artist_6 = ka6.artist_ID) LEFT JOIN artist ka7 ON song.artist_7 = ka7.artist_ID) LEFT JOIN artist ka8 ON song.artist_8 = ka8.artist_ID) LEFT JOIN artist ka9 ON song.artist_9 = ka9.artist_ID) LEFT JOIN artist ka10 ON song.artist_10 = ka10.artist_ID) LEFT JOIN artist ka11 ON song.artist_11 = ka11.artist_ID) LEFT JOIN artist ka12 ON song.artist_12 = ka12.artist_ID) LEFT JOIN sakushi ON song.sakushi_1 = sakushi.sakushi_ID) LEFT JOIN sakushi ss2 ON song.sakushi_2 = ss2.sakushi_ID) LEFT JOIN sakushi ss3 ON song.sakushi_3 = ss3.sakushi_ID) LEFT JOIN sakushi ss4 ON song.sakushi_4 = ss4.sakushi_ID) LEFT JOIN sakkyoku ON song.sakkyoku_1 = sakkyoku.sakkyoku_ID) LEFT JOIN sakkyoku sk2 ON song.sakkyoku_2 = sk2.sakkyoku_ID) LEFT JOIN sakkyoku sk3 ON song.sakkyoku_3 = sk3.sakkyoku_ID) LEFT JOIN sakkyoku sk4 ON song.sakkyoku_4 = sk4.sakkyoku_ID) LEFT JOIN hennkyoku ON song.hennkyoku_1 = hennkyoku.hennkyoku_ID) LEFT JOIN hennkyoku hk2 ON song.hennkyoku_2 = hk2.hennkyoku_ID) LEFT JOIN hennkyoku hk3 ON song.hennkyoku_3 = hk3.hennkyoku_ID) LEFT JOIN hennkyoku hk4 ON song.hennkyoku_4 = hk4.hennkyoku_ID) LEFT JOIN genre ON song.genre_1 = genre.genre_ID) LEFT JOIN genre gr2 ON song.genre_2 = gr2.genre_ID)←追加 LEFT JOIN tie_up ON song.tie_up_1 = tie_up.tie_up_ID) LEFT JOIN part ON song.part_1 = part.part_ID) ;');

みんなの回答

  • yambejp
  • ベストアンサー率51% (3827/7415)
回答No.2

join するのにかっこでくくる必要はないのでは? また正規化するにあたってはleft joinを多用するのはどうかと。 各IDが存在する前提でinner joinでつなぐことをお勧めします それと、PDOを利用するのに「SET NAMES utf8」を発行するのはやめるべき PHPのバージョンにもよりますがdsnで指定するかoptionを設定してください http://php.net/manual/ja/ref.pdo-mysql.connection.php

  • maiko0318
  • ベストアンサー率21% (1483/6969)
回答No.1

FROM (((((((((((((((((((((((((((( ここのカッコは増やしましたか?

関連するQ&A