我正在尝试使用fetch_assoc()但它给出了错误未定义的方法

时间:2018-06-21 11:20:57

标签: php pdo magento2

  

致命错误:未捕获错误:调用/var/www/html/magento22/mage.php:145中未定义的方法Magento \ Framework \ DB \ Statement \ Pdo \ Mysql :: fetch_assoc()

这是我的代码

$data = array();
/* ORDERS */

$result = $write->query('select c.sku, v.value, if(iv.qty = 0 and 
                            (if(iv.use_config_backorders = 1,\'Allow Backorder\',if(iv.backorders = 101,\'Allow pre-order\',\'No Backorder\'))) = \'No Backorder\'
                            , \'disabled\',\'enabled\') as status, iv.qty, 
                            if(iv.use_config_backorders = 1,\'Allow Backorder\',if(iv.backorders = 101,\'Allow pre-order\',\'No Backorder\')) as stock_status,
                            if(e.product_id is null,\'No\',\'Yes\') in_wow,
                            d.value as pre_date
                            from catalog_product_entity c
                            join catalog_product_entity_varchar v on v.entity_id = c.entity_id and v.attribute_id = 71
                            join catalog_product_entity_int s on s.entity_id = c.entity_id and s.attribute_id = 96
                            join cataloginventory_stock_item iv on iv.product_id = c.entity_id
                            join catalog_product_entity_varchar d on d.entity_id = iv.product_id and d.attribute_id = 182
                            left join catalog_category_product e on e.product_id = c.entity_id and category_id = 61
                            join catalog_product_website w on w.product_id = c.entity_id
                            where c.type_id = \'simple\' and w.website_id = 1 and s.value = 1
                        ');

if(is_object($result))
{   
    while ($resultsArray = $result->fetch_assoc())
    {
        if(empty($data))
           $data[] = array_keys($resultsArray);

        $data[] = $resultsArray;
    } var_dump($data);
}

没有连接问题,而且我的对象$ result具有值。所以没问题。

1 个答案:

答案 0 :(得分:0)

尝试更改:while ($resultsArray = $result->fetch_assoc())

收件人:while ($resultsArray = $result->fetchAll(\PDO::FETCH_ASSOC))

或者可以while ($resultsArray = $result->fetch(\PDO::FETCH_ASSOC))