I am trying to rewrite one of my old code to mysqli, because I am getting Allowed memory size exhausted errors. I read some tips to use mysqli_real_query, which will activate the query without loading all the records in RAM.
My old code:
<?
$sql = "SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.status = 1";
$query = $this->db->query($sql);
$results = $query->rows;
foreach ($results as $result) {
print_r("$result");
/* Output:
Array
(
[product_id] => 17763
[feed_product_id] => 0
[import_id] => 0
[name] => Name
[model] => MODEL
[sku] => 390348
[upc] => 390348
...
)
*/
}
?>
My new code so far:
<?
$db = mysqli_connect('localhost', 'username', 'pwd', 'db');
$sql = "SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.status = 1";
mysqli_real_query($db, $sql);
$result = mysqli_use_result($db);
while ($row = mysqli_fetch_row($result)) {
print("Test: " . $row);
/* Output:
(
[0] => 17763
[1] => 0
[2] => 0
[3] => Name
[4] => MODEL
[5] => 390348
[6] => 390348
*/
}
?>
How can I get the same results in the new code? My new array keys are 0, 1, 2, 3... instead of column names.