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/>";} ?>
source share