请告诉我我做错了什么?如何更好地与基地合作?连接工作,但我看不到基地的信息。我得到:
致命错误:调用未定义的方法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/>";}
?>