I'm trying to get content from a JSON file to put it in MySQL database using PHP, here is how I've been trying so far.
This is the JSON file AK.json
:
[
{
"CompanyName": "Logo Shirts Direct",
"StreetAddress": "1001 Commerce Parkway South Dr Suite E",
"Region": "Greenwood",
"State": "IN",
"PostCode": "46143",
"Phone": "(888) 341-5646"
},
{
"CompanyName": "L.F. GRAPHICS LLC",
"StreetAddress": "Paterson, ",
"Region": "Paterson",
"State": "NJ",
"PostCode": "07524",
"Phone": "(973) 240-7033"
},
{
"CompanyName": "Pacific Sportswear And Emblem Company",
"StreetAddress": "San Diego, ",
"Region": "Diego",
"State": "CA",
"PostCode": "92120",
"Phone": "(619) 281-6688"
}
]
and in PHP:
<?php
$filename = 'AK.json';
$content = file_get_contents($filename);
print_r(json_decode($content,true));
?>
When I execute this script nothing happens, also I tried the gettype()
function to get the type of the variable it returns NUll
.