我遇到了一次只能从 mysqli 打开一个结果集的问题。特别是,我试图在执行操作后循环选择查询并更新该查询中的列。
$db = new mysqli($DBServer, $DBUser, $DBPass , $DBName);
$sql = 'SELECT UPRN, POSTCODE FROM T_TEMP';
$stmt = $db->prepare($sql);
$stmt -> Execute();
<Create an array from the above select statement as i understand that mysqli can
only hold one result set at once (seems odd). I am unsure how to do this such that
i can then reference UPRN and POSTCODE later>
$stmt->Close();
$sql = 'update T_TEMP set LAT = ?, LONG = ? where UPRN = ?';
$stmt = $db ->prepare($sql);
<loop through that array built above grabbing UPRN and POSTCODE as you go through>
$postcode = urlencode(<Reference the postcode in the array>);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$postcode."&sensor=false";
$xml = simplexml_load_file($request_url);
$lat = round(floatval($xml->result->geometry->location->lat),4);
$long = round(floatval($xml->result->geometry->location->lng),4);
$stmt -> bind_param('ddi',$lat,$long,$UPRN);
$stmt -> Execute();
<end loop>
我正在努力将第一个查询的结果放入一个数组中,然后在循环中引用该数组,以便我可以设置值。非常感谢任何帮助!