0

基本上我要做的是运行一个 sql 语句,将查询结果的选择部分插入到最近创建的表中。我用mysql对其进行了测试并运行了这一行

INSERT INTO searched(imagetargetpath, gamename, gamedirectory, `like`, dislike) 
SELECT imagetargetpath, gamename, gamedirectory, `like`, dislike
FROM boardgamelist
WHERE gamename LIKE '%david%'

成功运行,但是当我从 phpmyadmin 提供的内容中将同一行放入 php 时,mysql_query 似乎没有运行

$sql = "INSERT INTO searched(imagetargetpath, gamename, gamedirectory,
`like`,   dislike) \n"
. "SELECT imagetargetpath, gamename, gamedirectory, `like`, dislike\n"
. "FROM boardgamelist\n"
. "WHERE gamename LIKE \'%david%\'";
    //copies query
    $copy_query = mysql_query($sql);

以前在我的代码中但是我确实有一个创建表“搜索”的mysql命令(确认工作)我忘记了如何处理不允许它运行的mysql命令?

4

2 回答 2

3

您忘记了换行符处的空格:

. "SELECT imagetargetpath, gamename, gamedirectory, `like`, dislike\n"
                                                                   ^---here
. "FROM boardgamelist\n"
                     ^---here

这将使最终的查询字符串为:

... dislikeFROM boargamelistWHERE

如果您甚至有基本的错误处理,例如

$copy_query = mysql_query($sql) or die(msyql_error());
                               ^^^^^^^^^^^^^^^^^^^^^^

您会被告知语法错误。

于 2012-04-20T18:14:50.833 回答
2

尝试这个

$sql = "INSERT INTO searched(imagetargetpath, gamename, gamedirectory, `like`, dislike) "
. "SELECT imagetargetpath, gamename, gamedirectory, `like`, dislike "
. "FROM boardgamelist WHERE gamename LIKE '%david%'";
于 2012-04-20T18:16:37.577 回答