-5

我正在尝试运行以下代码:

if ($result = $mysqli->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        $query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"
        $mysqli->query($query);
        $query = "DELETE FROM Table1 WHERE id=" . $row[1] . ";"
        $mysqli->query($query);
    }

    /* free result set */
    $result->close();
}

但它正在回归:

$mysqli->query($query);

有谁知道它可能是什么?

解析错误:语法错误,意外的 T_VARIABLE ...

4

3 回答 3

6

;在每一行的末尾添加:

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";";
                                                                                ^
$query = "DELETE FROM Table1 WHERE id=" . $row[1] . ";";
                                                       ^
于 2013-09-12T15:39:35.803 回答
2

好像您的查询有问题

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"

我认为应该是

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1];
于 2013-09-12T15:41:43.450 回答
1

他是对的,你在这一行缺少一个分号:

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"
于 2013-09-12T15:40:53.833 回答