6

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/>";}
?>
3
  • Call to undefined method mysqli::arrayQuery() - I mean error message is cear, isn't? Commented Jun 4, 2015 at 6:49
  • Can you post this function arrayQuery if you have it Commented Jun 4, 2015 at 6:50
  • Checking php.net/manual/en/book.mysqli.php reveals that arrayQuery is not available (the mysqli class does not have such a method). Also, it might be better to switch to PDO Commented Jun 4, 2015 at 6:53

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

MySQL 5.5.37, and connect as "mysqli". So this is not SQLite?
Nope...thats mysql database you are having, and since you have initialized "mysqli", the mysqli class does not have that method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.