PHP OOP和MySQLi连接=致命错误:调用未定义的方法mysqli :: arrayQuery()

时间:2015-06-04 06:47:22

标签: php mysql oop pdo mysqli

请告诉我我做错了什么?如何更好地与基地合作?连接工作,但我看不到基地的信息。我得到:

  

致命错误:调用未定义的方法mysqli :: arrayQuery()

我无法理解如何修复它,谷歌也没有帮助。

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

一点点修复,所有工作都完美无缺!谢谢大家!

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

1 个答案:

答案 0 :(得分:1)

您使用的数据库是什么? SQLitemysql

因为根据PHP DOCS,我想函数arrayQuery只能用于SQLite数据库