This work with a die statement. I put the die statement for testing. But once I remove the die statement for it to continue processing, I get the php fatal error. I tried to free the result set or close it, but it is still complaining.
See my code:
$mysqli = @new mysqli($db_host, $db_username, $db_password, $db_name);
$sql = "select * from table1";
$dataIndex = $mysqli->query($sql);
while ($result = $dataIndex->fetch_assoc())
{
$field1 = $result['index_short_name']."_field1";
$field2 = $result['index_short_name']."_field2";
$sqlData = "select new_date, ".$field1.", ".$field2." from table2";
$dataFund = $mysqli->query($sqlData);
while ($row = $dataFund->fetch_assoc())
{
$line = "";
$line .= $row['new_date'].",".$row[$field1].",".$row[$field2]."\n";
echo "<p>".$line."</p>";
}
die("here");
}
I replace the die("here") with $dataFund->close() and still error.
$dataIndex = $mysqli->query($sql);
if (!$dataIndex ) {
die('Invalid query: ' . mysql_error());
}
$dataFund = $mysqli->query($sqlData);
if (!$dataFund ) {
die('Invalid query: ' . mysql_error());
}
I think one of those loops might meet empty result and it causes that error