准备好的语句 - 将Mysql查询结果提取到数组中

时间:2017-08-21 15:52:38

标签: php html mysql

我正在实现一个准备好的语句,用于将查询结果提取到数组中,但是在fetch数组行中似乎出现了问题。

<?php
$cat_id = intval($_GET['cat_id']);
include '../sys/conn.php';

if($category= $conn->prepare("
SELECT t.term_id, t.name, t.slug, tm.term_id, tm.name, count(tr.object_id) as total_products
FROM mg_terms t
JOIN mg_term_taxonomy tx ON tx.term_id = t.term_id
LEFT JOIN mg_term_relationships tr ON tr.term_taxonomy_id=tx.term_taxonomy_id
LEFT JOIN mg_terms tm ON tm.term_id = tx.parent
WHERE t.term_id=?
GROUP BY t.term_id")) {

    $category->bind_param('i', $cat_id);
    $category->execute();
    $category->bind_result($cat_id, $cat_name, $cat_slug, $par_id, $par_name, $count);
    $category->fetch();
    $array = $category->fetch_array(MYSQL_NUM); //line error
    $category->close();
}

我遇到的错误是:

Fatal error: Call to undefined method mysqli_stmt::fetch_array()

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你必须学习PHP OOP ..这将帮助你,你将以一种简单的方式做任何你需要的事情。 请点击以下链接。

https://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762