php - 我正在尝试使用 fetch_assoc() 但它给出了错误未定义的方法
问题描述
致命错误:未捕获错误:调用 /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 也有值。所以没问题。
解决方案
尝试改变:while ($resultsArray = $result->fetch_assoc())
到:while ($resultsArray = $result->fetchAll(\PDO::FETCH_ASSOC))
或者可以通过while ($resultsArray = $result->fetch(\PDO::FETCH_ASSOC))
推荐阅读
- csv - 使用 sed 更改分隔符
- node.js - AJAX 在客户端输入上运行 nodejs 文件
- python - 批量加载H5PY文件
- c# - 如何使用 FlaUI 在 Visual Studio 2019 中使用视图而不是窗口进行测试?
- c# - 如何在异步任务中使用拖放
- spring - Spring Boot @ControllerAdvice @ExceptionHandler 内容类型通过注解
- c# - 如何在 Chrome 中打开 docx 而不是下载
- oracle - OR 或 IN 等操作数中不允许外连接运算符 (+) 的解决方案
- python - Python:从旋转框中读取数字并执行以下命令
- c# - 有没有办法同时使用 LINQ 对两个属性进行排序