I have a cron job that runs a few mysqli queries and then stores the info in an array for later use. When the cron job runs, the mysqli queries return no syntax errors. I did a print_r of the result and it shows that there were multiple rows in the mysqli object but when the foreach loop ran, no info was extracted from the result object. The funny part? I run the same script in the browser to debug and everything works perfectly. Below is the code. (Browser PHP version 5.7, server/cron PHP version 5.3)
$mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
$emailContent = array();
$result = $mysqli->query("SELECT * FROM emailType ORDER BY emailNumber");
print_r($result);
foreach($result as $row) {
print_r($row);
$emailNumber = $row['emailNumber'];
$email = array(
"emailName" => $row['emailName'],
"emailSlug" => $row['emailSlug'],
"emailDescription" => $row['emailDescription'],
"link" => $row['link'],
"subject" => $row['subject'],
"content1" => $row['content1'],
"content2" => $row['content2']
);
$emailContent[$emailNumber] = $email;
}
I included the return of the print_r methods from above. When running the cron, the print_r($result) returns this:
mysqli_result Object
(
[current_field] => 0
[field_count] => 16
[lengths] =>
[num_rows] => 8
[type] => 0
)
While the print_r($row) returns nothing. When running this through a browser I get the same info print_r($result) but I also get a mysql record for print_r($row). It is important to note that I get no error at all.