I am currently making a WordPress plugin and trying to select a few values from WooCommerce database and all I keep getting is the same error. What might be wrong?
My Code:
function prntPage()
{
//Connect is defined somewhere else
$query = "SELECT * FROM `wp_woocommerce_order_items`";
$result = mysqli_query($conn,$query);
while($row = $result->mysqli_fetch_assoc()) {
echo "id: " . $row["order_item_id"]. " - Product Name: " . $row["order_item_name"]. " - Order_ID" . $row["order_id"]. "<br>";
}
}
The Error:
Fatal error: Uncaught Error: Call to undefined method mysqli_result::mysqli_fetch_assoc() in C:\xampp\htdocs\ExamenProject\wp-content\plugins\drukkebaasjes-sizedata\drukkebaasjes-sizedata.php:54 Stack trace: #0 C:\xampp\htdocs\ExamenProject\wp-includes\class-wp-hook.php(286): prntPage('') #1 C:\xampp\htdocs\ExamenProject\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 C:\xampp\htdocs\ExamenProject\wp-includes\plugin.php(453): WP_Hook->do_action(Array) #3 C:\xampp\htdocs\ExamenProject\wp-admin\admin.php(224): do_action('toplevel_page_p...') #4 {main} thrown in C:\xampp\htdocs\ExamenProject\wp-content\plugins\drukkebaasjes-sizedata\drukkebaasjes-sizedata.php on line 54
$result->fetch_assoc()
ormysqli_fetch_assoc($result)
. Every time you get an error likeundefined method
orundefined function
you should check the manuals – Paul Spiegelmysqli
directly, you should look into using Wordpress db-class instead. You can read about it here: codex.wordpress.org/Class_Reference/wpdb – Magnus Eriksson