0

connecttodatabase.phpにはmysql接続のコードが含まれ、 index.phpにはwebServiceのコードが含まれていますが、SQLエラーが発生しました:

SQL 構文にエラーがあります。3 行目の ' desc, cat, price FROM itmes '付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。

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>
4

1 に答える 1