当我尝试运行php时,我收到以下错误消息:
无效的查询:您的SQL语法有错误;查看手册 对应于您的MySQL服务器版本的正确语法, 在第1行的“查询”附近使用
这是我的代码。我看过类似的问题,但似乎没有任何效果。
<?php
require("phpsqlajax_dbinfo.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysqli_connect ('127.0.0.1', 'chris', 'banks');
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysqli_select_db($connection, 'business');
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysqli_query($connection, 'query');
if (!$result) {
die('Invalid query: ' . mysqli_error($connection));
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// Add to XML document node
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id",$row['id']);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("type", $row['type']);
}
echo $dom->saveXML();
?>
答案 0 :(得分:0)
更改
$result = mysqli_query($connection, 'query');
收件人
$result = mysqli_query($connection, $query);
WHERE 1
也没有多大意义。
答案 1 :(得分:0)
1。首先,不要在同一位置使用mysqli和mysql时混合使用驱动程序。首选 mysqli ,因为mysql已弃用。
$ result = mysqli_query($ connection,'query');
收件人
$ result = mysqli_query($ connection,$ query);
因为您已将SQL查询存储在$ query变量中。
3。避免使用“ 其中1 ”-只需使用 SELECT * FROM标记 尽管它似乎可以在phpmyadmin中工作,但是避免在php代码中使用它。
希望它能起作用.. !!!