gpt4 book ai didi

PHP OOP 和 MySQLi 连接 = fatal error :调用未定义的方法 mysqli::arrayQuery()

转载 作者:可可西里 更新时间:2023-11-01 06:51:01 24 4
gpt4 key购买 nike

请告诉我我做错了什么?以及如何更好地与基地合作?连接有效,但我看不到来自基地的信息。我只是得到:

Fatal error: Call to undefined method 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/>";}
?>

最佳答案

您使用的是什么数据库? SQLite 还是 mysql ?

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

关于PHP OOP 和 MySQLi 连接 = fatal error :调用未定义的方法 mysqli::arrayQuery(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30636829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com