PHP OOP和MySQLi连接=致命错误:调用未定义的方法sqmyli::arrayQuery()
16lz
2021-01-22
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()
致命错误:调用未定义的mymethod sqli::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/>";}
?>
1 个解决方案
#1
1
What database are you using? SQLite
or mysql
?
您正在使用什么数据库?SQLite或mysql吗?
Because as per the PHP DOCS, I guess the function arrayQuery
can be used only for SQLite databases
因为根据PHP文档,我猜想函数arrayQuery只能用于SQLite数据库
更多相关文章
- MySQL官网示例数据库emploees分析使用
- mysql——数据库设计中int与varchar中的长度含义
- java链接数据库--Mysql
- 数据库_MySQL_复杂SQL的书写顺序与执行过程
- mysql dos命令 创建表单,选择数据库
- Spring Security ACL使用MySQL配置与数据库脚本
- 需要从mysql数据库中获得productdata。
- 数据库行转列和列转行小例子
- MySQL数据库储存bit类型的值报错