Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数据库表示存储api数据时出现语法错误或访问冲突_Php_Mysql_Json - Fatal编程技术网

Php 数据库表示存储api数据时出现语法错误或访问冲突

Php 数据库表示存储api数据时出现语法错误或访问冲突,php,mysql,json,Php,Mysql,Json,我正在从ZomatoAPI获取一些数据,并将其存储在我的php变量中 Zomato api数据: [19]=> array(1) { ["restaurant"]=> array(39) { ["R"]=> array(3) { ["has_menu_status"]=> array(2) {

我正在从ZomatoAPI获取一些数据,并将其存储在我的php变量中

Zomato api数据:

[19]=>
    array(1) {
      ["restaurant"]=>
      array(39) {
        ["R"]=>
        array(3) {
          ["has_menu_status"]=>
          array(2) {
            ["delivery"]=>
            int(-1)
            ["takeaway"]=>
            int(-1)
          }
          ["res_id"]=>
          int(16594994)
          ["is_grocery_store"]=>
          bool(false)
        }
        ["apikey"]=>
        string(32) "*********"
        ["id"]=>
        string(8) "16594994"
        ["name"]=>
        string(14) "Hakataya Ramen"
        ["url"]=>
        string(118) "https://www.zomato.com/brisbane/hakataya-ramen-brisbane-cbd?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1"
        ["location"]=>
        array(9) {
          ["address"]=>
          string(70) "Myer Centre, Level A, Shop 16, 91 Queen Street, Brisbane CBD, Brisbane"
          ["locality"]=>
          string(11) "Myer Centre"
          ["city"]=>
          string(8) "Brisbane"
          ["city_id"]=>
          int(298)
          ["latitude"]=>
          string(14) "-27.4711666167"
          ["longitude"]=>
          string(14) "153.0255184695"
          ["zipcode"]=>
          string(4) "4000"
          ["country_id"]=>
          int(14)
          ["locality_verbose"]=>
          string(21) "Myer Centre, Brisbane"
        }
        ["switch_to_order_menu"]=>
        int(0)
        ["cuisines"]=>
        string(15) "Japanese, Ramen"
        ["timings"]=>
        string(12) "9 AM to 9 PM"
        ["average_cost_for_two"]=>
        int(40)
        ["price_range"]=>
        int(2)
        ["currency"]=>
        string(1) "$"
        ["highlights"]=>
        array(11) {
          [0]=>
          string(11) "Credit Card"
          [1]=>
          string(5) "Lunch"
          [2]=>
          string(4) "Cash"
          [3]=>
          string(18) "Takeaway Available"
          [4]=>
          string(20) "No Alcohol Available"
          [5]=>
          string(6) "Dinner"
          [6]=>
          string(10) "Debit Card"
          [7]=>
          string(21) "Wheelchair Accessible"
          [8]=>
          string(19) "Vegetarian Friendly"
          [9]=>
          string(19) "Gluten Free Options"
          [10]=>
          string(14) "Indoor Seating"
        }
        ["offers"]=>
        array(0) {
        }
        ["opentable_support"]=>
        int(0)
        ["is_zomato_book_res"]=>
        int(0)
        ["mezzo_provider"]=>
        string(5) "OTHER"
        ["is_book_form_web_view"]=>
        int(0)
        ["book_form_web_view_url"]=>
        string(0) ""
        ["book_again_url"]=>
        string(0) ""
        ["thumb"]=>
        string(131) "https://b.zmtcdn.com/data/reviews_photos/67d/50ccdf6b24269b73fdaf839e5774467d.jpg?fit=around%7C200%3A200&crop=200%3A200%3B%2A%2C%2A"
        ["user_rating"]=>
        array(5) {
          ["aggregate_rating"]=>
          string(3) "4.2"
          ["rating_text"]=>
          string(9) "Very Good"
          ["rating_color"]=>
          string(6) "5BA829"
          ["rating_obj"]=>
          array(2) {
            ["title"]=>
            array(1) {
              ["text"]=>
              string(3) "4.2"
            }
            ["bg_color"]=>
            array(2) {
              ["type"]=>
              string(4) "lime"
              ["tint"]=>
              string(3) "700"
            }
          }
          ["votes"]=>
          int(110)
        }
        ["all_reviews_count"]=>
        int(47)
        ["photos_url"]=>
        string(132) "https://www.zomato.com/brisbane/hakataya-ramen-brisbane-cbd/photos?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1#tabtop"
        ["photo_count"]=>
        int(56)
        ["menu_url"]=>
        string(162) "https://www.zomato.com/brisbane/hakataya-ramen-brisbane-cbd/menu?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1&openSwipeBox=menu&showMinimal=1#tabtop"
        ["featured_image"]=>
        string(81) "https://b.zmtcdn.com/data/reviews_photos/67d/50ccdf6b24269b73fdaf839e5774467d.jpg"
        ["has_online_delivery"]=>
        int(0)
        ["is_delivering_now"]=>
        int(0)
        ["store_type"]=>
        string(0) ""
        ["include_bogo_offers"]=>
        bool(true)
        ["deeplink"]=>
        string(28) "zomato://restaurant/16594994"
        ["is_table_reservation_supported"]=>
        int(0)
        ["has_table_booking"]=>
        int(0)
        ["events_url"]=>
        string(132) "https://www.zomato.com/brisbane/hakataya-ramen-brisbane-cbd/events#tabtop?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1"
        ["phone_numbers"]=>
        string(12) "07 3012 9002"
我的php变量:

        $res_id = $search['restaurants'][$i]['restaurant']['R']['res_id'];
        $res_name = $search['restaurants'][$i]['restaurant']['name'];
        $res_link = $search['restaurants'][$i]['restaurant']['url'];
        $res_phoneNo = $search['restaurants'][$i]['restaurant']['phone_numbers'];
        $res_aggregrateRating = $search['restaurants'][$i]['restaurant']['user_rating']['aggregate_rating'];
        $res_ratingText = $search['restaurants'][$i]['restaurant']['user_rating']['rating_text'];
        $res_cuisines = $search['restaurants'][$i]['restaurant']['cuisines'];
        $res_photos = $search['restaurants'][$i]['restaurant']['photos_url'];
        $res_priceRange = $search['restaurants'][$i]['restaurant']['price_range'];
        $res_currency = $search['restaurants'][$i]['restaurant']['currency'];
        $city = $search['restaurants'][$i]['restaurant']['location']['city'];
        $city_id = $search['restaurants'][$i]['restaurant']['location']['city_id'];
        $locality = $search['restaurants'][$i]['restaurant']['location']['locality'];
        $timings = $search['restaurants'][$i]['restaurant']['timings'];
        $res_menu = $search['restaurants'][$i]['restaurant']['menu_url'];
        $res_averageCostForTwo = $search['restaurants'][$i]['restaurant']['average_cost_for_two'];
        $res_establishment = $search['restaurants'][$i]['restaurant']['establishment'][0];
        $res_address = $search['restaurants'][$i]['restaurant']['location']['address'];
        $countForHighlights = count($search['restaurants'][$i]['restaurant']['highlights']);
我的数据库代码位于与上面相同的文件中:

try {
            $sql = "INSERT INTO basicinfo (res_id, `name`, `address`, locality, city, city_id, cuisines, timings, average_cost_for_two, price_range,
currency, aggregrate_rating, rating_text, photo_url, menu_url, phone_number, establishment, `url`)
VALUES ($res_id, $res_name, $res_address, $locality, $city, $city_id, $res_cuisines, $timings, $res_averageCostForTwo, $res_priceRange, $res_currency, $res_aggregrateRating, $res_ratingText, $res_photos
 , $res_menu, $res_phoneNo, $res_establishment, $res_link)";

            $conn->exec($sql);
            echo 'record added succesfully';
        } catch (PDOException $e) {
            echo $sql . "<br>" . $e->getMessage();
        }

如果需要更多信息,请告诉我。谢谢。

幸运的是,经过一段时间的思考,我意识到我应该在插入值时使用
'

所以我改变了我的路线:

$sql = "INSERT INTO basicinfo (res_id, `name`, `address`, locality, city, city_id, cuisines, timings, average_cost_for_two, price_range,
currency, aggregrate_rating, rating_text, photo_url, menu_url, phone_number, establishment, `url`)
VALUES ($res_id, $res_name, $res_address, $locality, $city, $city_id, $res_cuisines, $timings, $res_averageCostForTwo, $res_priceRange, $res_currency, $res_aggregrateRating, $res_ratingText, $res_photos
 , $res_menu, $res_phoneNo, $res_establishment, $res_link)";
致:

而且,它现在起作用了

$sql = "INSERT INTO basicinfo (res_id, `name`, `address`, locality, city, city_id, cuisines, timings, average_cost_for_two, price_range,
currency, aggregrate_rating, rating_text, photo_url, menu_url, phone_number, establishment, `url`)
VALUES ($res_id, $res_name, $res_address, $locality, $city, $city_id, $res_cuisines, $timings, $res_averageCostForTwo, $res_priceRange, $res_currency, $res_aggregrateRating, $res_ratingText, $res_photos
 , $res_menu, $res_phoneNo, $res_establishment, $res_link)";
$sql = "INSERT INTO basicinfo (res_id, `name`, `address`, locality, city, city_id, cuisines, timings, average_cost_for_two, price_range,
currency, aggregrate_rating, rating_text, photo_url, menu_url, phone_number, establishment, `url`)
VALUES ('$res_id', '$res_name', '$res_address', '$locality', '$city', '$city_id', '$res_cuisines', '$timings', '$res_averageCostForTwo', '$res_priceRange', '$res_currency', '$res_aggregrateRating', '$res_ratingText', '$res_photos'
 , '$res_menu', '$res_phoneNo', '$res_establishment', '$res_link')";