我正在尝试使用 fetch_assoc() 但它给出了错误 undefined method
I am trying to use fetch_assoc() but it gives error undifined method
Fatal error: Uncaught Error: Call to undefined method Magento\Framework\DB\Statement\Pdo\Mysql::fetch_assoc() in /var/www/html/magento22/mage.php:145
这是我的代码
$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 也有值。所以没问题。
尝试更改:while ($resultsArray = $result->fetch_assoc())
至:while ($resultsArray = $result->fetchAll(\PDO::FETCH_ASSOC))
或者 while ($resultsArray = $result->fetch(\PDO::FETCH_ASSOC))
Fatal error: Uncaught Error: Call to undefined method Magento\Framework\DB\Statement\Pdo\Mysql::fetch_assoc() in /var/www/html/magento22/mage.php:145
这是我的代码
$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 也有值。所以没问题。
尝试更改:while ($resultsArray = $result->fetch_assoc())
至:while ($resultsArray = $result->fetchAll(\PDO::FETCH_ASSOC))
或者 while ($resultsArray = $result->fetch(\PDO::FETCH_ASSOC))