How to Insert JSON into mysql table with PHP
I have tried many sites to find how to insert json in mysql but i did not find any proper solution. Can you help me to insert the bellow json in mysql table and also tell me the required names for column in my table.
{
"request" : ` {
"Target" : "Affiliate_Report",
"Format" : "json",
"Service" : "HasOffers",
"Version" : "2",
"NetworkId" : "network_id",
"Method" : "getConversions",
"api_key" : "api_key",
"fields" : ["Stat.affiliate_info1", "Offer.name"],
"limit" : "1"
},
"response" : {
"status" : 1,
"httpStatus" : 200,
"data" : {
"page" : 1,
"current" : 1,
"count" : 82,
"pageCount" : 82,
"data" : [{
"Stat" : {
"affiliate_info1" : "aashiq"
},
"Offer" : {
"name" : "App Download - Paytm - Android - IN - Incent"
}
}
],
"dbSource" : "branddb"
},
"errors" : [],
"errorMessage" : null
}
}
i need to insert the data :aashiq, App Download - Paytm - Android - IN - Incent
from the above json
Answer
Solution:
I will give a try. Bear with me cause my PHP is a bit rusty... So let's say
$mydata
is you array object storing the JSON. Then:Create a MySQL database with a database called
offers
with a tableoffer
and three fields: anID
that will be autoincrement,affiliate VARCHAR
,final_offer VARCHAR
I believe the code above is more or less correct