Insert Json data into SQL Server 2012 with PHP -
i parsing data json link insert 1 table in sql server 2012. parsing working well, problem inserting of data sql server.
sample json data:
"results": [ { "name": "the jpt on more - commercial transformation", "metrics": { "video": { "playthrough_75": "2981", "plays": "5466", "time_watched": "4030502288", "playthrough_100": "2288", "uniq_plays": { "monthly_uniqs": "4731", "daily_uniqs": "5136", "weekly_uniqs": "4991" },
script:
$context = stream_context_create($opts); $content = file_get_contents($url, false, $context); $json = json_decode($content, true); foreach($json['results'] $item) { $videoname = $item['name']; $playthrough_75 = $item['metrics']['video']['playthrough_75']; $plays = $item['metrics']['video']['plays']; $time_watched = $item['metrics']['video']['time_watched']; $playthrough_100 = $item['metrics']['video']['playthrough_100']; $plays_monthly_uniqs = $item['metrics']['video']['uniq_plays']['monthly_uniqs']; $plays_daily_uniqs = $item['metrics']['video']['uniq_plays']['daily_uniqs']; $plays_weekly_uniqs = $item['metrics']['video']['uniq_plays']['weekly_uniqs']; $servername = "server_name"; $connectioninfo = array("database"=>"web_analytics"); $conn = sqlsrv_connect($servername, $connectioninfo); *insert sql script here* }
so script above, stored each field variable , execute query below. how execute using php?
$sql = "insert ooyala_analytics([videoname] ,[videoid] ,[playthrough_75] ,[plays] ,[time_watched] ,[playthrough_100] ,[plays_monthly_uniqs] ,[plays_daily_uniqs] ,[plays_weekly_uniqs] ,) values('$videoname' ,'$videoid' ,'$playthrough_75' ,'$plays' ,'$time_watched' ,'$playthrough_100' ,'$plays_monthly_uniqs' ,'$plays_daily_uniqs' ,'$plays_weekly_uniqs' ')"; }
Comments
Post a Comment