Created
April 14, 2014 14:30
-
-
Save itsbalamurali/10653341 to your computer and use it in GitHub Desktop.
Game Metadata Import Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con=mysqli_connect("localhost","root","yourass1994","games"); | |
// Check connection | |
if (mysqli_connect_errno()) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
// Change character set to utf8 | |
mysqli_set_charset($con,"utf8"); | |
// Does not support flag GLOB_BRACE | |
function rglob($pattern, $flags = 0) { | |
$files = glob($pattern, $flags); | |
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { | |
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags)); | |
} | |
return $files; | |
} | |
$meta_array = rglob('./games/*/__metadata__.json'); | |
//echo "INSERT INTO games (uuid, created, name, description, thumbnail_url, rating, category, swf_url,slug, resolution, height, width, thumbnail_large_url, video_url, screen1_thumb, screen2_thumb, screen3_thumb, screen4_thumb, popularity, instructions) VALUES "; | |
$i = 0; | |
foreach ($meta_array as $meta) { | |
$game = explode("/", $meta); | |
//print_r($game); | |
$game_name = $game[2]; | |
$json = json_decode(file_get_contents($meta)); | |
$desc = mysqli_real_escape_string($con, $json->description); | |
//exit(); | |
//echo $json->name; | |
$game_swf = $json->swf_url; | |
$swf = mysqli_real_escape_string($con, $game_swf); | |
$sql = "INSERT INTO games (uuid, created, name, description, thumbnail_url, rating, category, swf_url,slug, resolution, height, width, thumbnail_large_url, video_url, screen1_thumb, screen2_thumb, screen3_thumb, screen4_thumb, popularity, instructions) VALUES ('".$json->uuid."', '".$json->created."', '".mysqli_real_escape_string($con, $json->name)."', '".$desc."', '".$json->thumbnail_url."', '".$json->rating."', '".$json->category."', '".$swf."','".$json->slug."', '".$json->resolution."', ".$json->height.", ".$json->width.", '".$json->thumbnail_large_url."', '".$json->video_url."', '".$json->screen1_thumb."', '".$json->screen2_thumb."', '".$json->screen3_thumb."', '".$json->screen4_thumb."', ".$json->recommendation.", '".mysqli_real_escape_string($con, $json->instructions)."')"; | |
//echo $sql; | |
//mysqli_query($con,$sql); | |
echo $i++.". Importing data for game {".$json->name."}.... \n"; | |
if (!mysqli_query($con,$sql)) | |
{ | |
die('Error: ' . mysqli_error($con)); | |
} | |
echo "------>>>>>>Done>>>>>>-------- \n"; | |
} | |
echo "{-------- Data Importing Done --------} \n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment