下面是我能够在 PhpMyAdmin 中成功运行的 SQL 查询。[类似于IMDB数据库的多表数据]
SELECT
`data`.`code`,
`data`.`movie`,
`movies`.`id`,
`movies`.`name`,
`data`.`person`,
`persons`.`name`,
`persons`.`code`,
`data`.`mode`,
`modes`.`name`
FROM
`data`
INNER JOIN `movies` ON (`data`.`movie` = `movies`.`id`)
INNER JOIN `persons` ON (`data`.`code` = `persons`.`code`)
INNER JOIN `modes` ON (`data`.`mode` = `modes`.`code`)
where `data`.`movie`=1
以下是由 PhpMyAdmin(创建 PHP 代码按钮)从上述命令生成的 PHP 代码,但在 PHP 页面(网页)中使用时未获取任何结果,
$sql = "SELECT \n"
. " `data`.`code`,\n"
. " `data`.`movie`,\n"
. " `movies`.`id`,\n"
. " `movies`.`name`,\n"
. " `data`.`person`,\n"
. " `persons`.`name`,\n"
. " `persons`.`code`,\n"
. " `data`.`mode`,\n"
. " `modes`.`name`\n"
. "FROM\n"
. " `data`\n"
. " INNER JOIN `movies` ON (`data`.`movie` = `movies`.`id`)\n"
. " INNER JOIN `persons` ON (`data`.`code` = `persons`.`code`)\n"
. " INNER JOIN `modes` ON (`data`.`mode` = `modes`.`code`)\n"
. "where `data`.`movie`=1 LIMIT 0, 30 ";