PHP OOP and MySQLi connection = Fatal error: call to undefined method mysqli :: arrayQuery ()

Please tell me what I did wrong? And what is the best way to work with the database? The connection works, but I do not see the information from the database. I just get:

Fatal error: call to undefined method mysqli :: arrayQuery ()

I canโ€™t figure out how to fix this, Google didnโ€™t help either.

<?php class Proc{ protected $DB; function __construct(){ $this->DB=new mysqli('localhost', 'user', 'password', 'basename'); $this->DB->query("set names utf8");} function __destruct(){unset($this->DB);} function GetAll(){ $sql="SELECT * FROM users"; $result = $this->DB->arrayQuery($sql, SQLITE_ASSOC); return $result;} } $Yo = new Proc(); $users = $Yo->GetAll(); echo "All users: ".count($users); foreach ($users as $user){ $id = $user["ID"]; $n = $user["Name"]; echo "{$id} - {$n}<br/>";} ?> 

A small fix and everything works fine! Thanks everyone!

 <?php class Proc{ protected $DB; function __construct(){ $this->DB=new PDO("mysql:host=localhost;dbname=basename", user, password); $this->DB->query("set names utf8");} function __destruct(){unset($this->DB);} function GetAll(){ $sql="SELECT * FROM users"; $result = $this->DB->query($sql); return $result;} } $Yo = new Proc(); $users = $Yo->GetAll(); foreach ($users as $user){ $id = $user["ID"]; $n = $user["Name"]; echo "{$id} - {$n}<br/>";} ?> 
+6
source share
1 answer

What database are you using? SQLite or mysql ?

Because according to PHP DOCS , I think the arrayQuery function can only be used for SQLite databases

+1
source

Source: https://habr.com/ru/post/988494/


All Articles