Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Please tell me what I've done wrong? And how to work with base better? Connection works, but I can not see information from base. I just get:

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

I can't understand how to fix it, 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 little fix and all work perfect! Thanks to all!

<?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/>";}
?>
like image 942
Baaakaaa Avatar asked Jun 04 '15 06:06

Baaakaaa


1 Answers

What database are you using? SQLite or mysql ?

Because as per the PHP DOCS, I guess the function arrayQuery can be used only for SQLite databases

like image 127
Abhinav Avatar answered Nov 14 '22 23:11

Abhinav