Php 我试图使用fetch_assoc(),但它给出了错误未定义的方法
致命错误:未捕获错误:调用/var/www/html/magento22/mage.php:145中未定义的方法Magento\Framework\DB\Statement\Pdo\Mysql::fetch_assoc() 这是我的密码Php 我试图使用fetch_assoc(),但它给出了错误未定义的方法,php,pdo,magento2,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 (i
$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);
}
没有连接问题,而且我的object$result也有值。所以这没问题。尝试更改:while($resultsArray=$result->fetch\u assoc())
收件人:while($resultsArray=$result->fetchAll(\PDO::FETCH\u ASSOC))
或者可以通过
而($resultsArray=$result->fetch(\PDO::fetch\u ASSOC))
在PDO本身中没有fetch\u ASSOC()
,您需要fetch(PDO::fetch\u ASSOC)
。但不确定Magento…我已经尝试过了,但它没有从$result中提取任何值,但$result有许多值。如何将Magento 1方法fetch_assoc()转换为Magento 2。要点是这样的。您应该尝试在DB后端(phpmyadmin)中运行该查询,看看它能给您带来什么。。。。