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/>";}
?>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With