I am fetching some data from Zomato API and storing it my php variables.
The Zomato api data:
[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"
My php variables:
$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']);
My database code in the same file as above:
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();
}
I keep getting the error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Phoenix Chinese Restaurant, Brisbane Quarter, Level 2, 300 George Street, Bri...' at line 3
My values in $sql
I try printing on my website to see what it has stored are given below:
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 (19118032, Brisbane Phoenix Chinese Restaurant, Brisbane Quarter, Level 2, 300 George Street, Brisbane CBD, Brisbane, Brisbane Quarter, Brisbane, 298, Asian, Chinese, Yum Cha, 11:30am – 3pm, 5:30pm – 10pm (Mon-Sat),11:30am – 3pm (Sun), 80, 3, $, 3.8, Good, https://www.zomato.com/brisbane/brisbane-phoenix-chinese-restaurant-brisbane-cbd/photos?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1#tabtop , https://www.zomato.com/brisbane/brisbane-phoenix-chinese-restaurant-brisbane-cbd/menu?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1&openSwipeBox=menu&showMinimal=1#tabtop, 07 5515 0540, Casual Dining, https://www.zomato.com/brisbane/brisbane-phoenix-chinese-restaurant-brisbane-cbd?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1)
If any more information is needed please let me know. Thanks.