0
我建立簡單的WebService我的web應用程序只包含兩個PHP文件connecttodatabase.php包含MySQL連接的代碼和的index.php包含我的web服務的代碼,但我得到了SQL錯誤:MySQL服務器版本問題
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, cat, price FROM itmes' at line 3
connecttodatabase.php
<?php
$requesturi = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$pos = strpos($requesturi, "localhost:99/self/index.php");
$hostname = "localhost";
$database = "self";
$username = "root";
$password = "";
$self = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
的index.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
//get data
require_once('connecttodatabase.php');
mysql_select_db($database, $self);
//build query
$query =
"SELECT
name,
desc,
cat,
price
FROM itmes";
$rsPackages = mysql_query($query, $self) or
die(mysql_error());
$arRows = array();
while ($row_rsPackages = mysql_fetch_assoc($rsPackages)) {
array_push($arRows, $row_rsPackages);
}
header('Content-type: application/json');
echo json_encode($arRows);
?>
</body>
</html>