I have been trying to solve this for hours now and just can't figure out what I am doing wrong here. The loop won't cycle (nothing is being echo'd), but when I run the query in phpmyadmin it works fine. Also the database info is fine. Unfortunately mysqli doesn't output any error at all...
Any help is greatly appreciated!
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
set_time_limit(0);
$db = new mysqli('localhost', 'xxx', 'xxx', 'xxx');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT * FROM
`zips`
SQL;
if(!$result = $db->query($sql,MYSQLI_STORE_RESULT)){
echo $result->num_rows; // nothing outputted here
while($row = $result->fetch_assoc()){
$zip = $row['zip'];
$url = "http://www.webservicex.net/uszip.asmx/GetInfoByZIP?USZip=".$zip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$xmlobj = simplexml_load_string($result);
$city = $xmlobj->Table->CITY;
$state = $xmlobj->Table->STATE;
$timezone = $xmlobj->Table->TIME_ZONE;
$areacode = $xmlobj->Table->AREA_CODE;
echo "city:" . $city;die();
$sql2 = <<<SQL
INSERT INTO zips
(zip,city,state,timezone,areacode)
VALUES('{$zip}','{$city}','{$state}', '{$timezone}', '{$areacode}')
SQL;
if(!$result2 = $db->query($sql2)){
die('There was an error running the query [' . $db->error . ']');
}
}
} else {
die('There was an error running the query [' . $db->error . ']');
}