84669 orang belajar
152542 orang belajar
20005 orang belajar
5487 orang belajar
7821 orang belajar
359900 orang belajar
3350 orang belajar
180660 orang belajar
48569 orang belajar
18603 orang belajar
40936 orang belajar
1549 orang belajar
1183 orang belajar
32909 orang belajar
Kod saya terus mendapat ralat: Ralat maut: Panggilan ke fungsi ahli exec() pada nol
<?php
kelas db{
peribadi $dbConfig = [
'db' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'dbname' => 'satu',
'pengguna' => 'root',
'password' => '1234',//
'charset' => 'utf'
];
awam $insertId = null;
awam $num = 0;
peribadi statik $instance = null;
noll;
fungsi peribadi __construct($params){
$this->dbConfig = array_merge($this->dbConfig,$params);
;
; $this-config> }
fungsi peribadi __clone(){
}
fungsi awam getInstance(){
if(!self::$instance instanceof self){
self:=$instance baru( );
kembalikan diri::$instance;
public function connect(){
try{
$dsn = "{$this->dbConfig['dbt']}: ->dbConfig['host']};
port = {$this->dbConfig['port']};
charset = {$this->dbConfig['charset']}";
$this->conn = pdo baharu($dsn,$this->dbConfig['user'],$this->dbConfig['password']);
catch(PDOExecption $e){
die("数据库连接失败".$e->getMessage());
// 完成数据表成数据表的墙除
// 返回受影响的记录 如果新增还返回新增主键id
public function exec($sql){
$num = $this->conn->exec($sql);
// 如协果
$this->num = $rum;//返回受影响的记录
;pertanyaan ($sql)->fetch(PDO::FETCH_ASSOC);
public function fetchALL($sql){
return $this->conn->query($sql)->fetch( PDO::FETCH_ASSOC);
<?php
kelas db{
peribadi $dbConfig = [
'db' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'dbname' => 'satu',
'pengguna' => 'root',
'password' => '1234',//
'charset' => 'utf'
];
awam $insertId = null;
awam $num = 0;
peribadi statik $instance = null;
noll;
fungsi peribadi __construct($params){
$this->dbConfig = array_merge($this->dbConfig,$params);
;
; $this-config> }
fungsi peribadi __clone(){
}
fungsi awam getInstance(){
if(!self::$instance instanceof self){
self:=$instance baru( );
}
kembalikan diri::$instance;
}
public function connect(){
try{
$dsn = "{$this->dbConfig['dbt']}: ->dbConfig['host']};
port = {$this->dbConfig['port']};
charset = {$this->dbConfig['charset']}";
$this->conn = pdo baharu($dsn,$this->dbConfig['user'],$this->dbConfig['password']);
}
catch(PDOExecption $e){
die("数据库连接失败".$e->getMessage());
}
}
// 完成数据表成数据表的墙除
// 返回受影响的记录 如果新增还返回新增主键id
public function exec($sql){
$num = $this->conn->exec($sql);
// 如协果
jika ($ num & gt; 0) { // 如果 是 新增 操作 初始化 新 增 主键 id 的 属性 if (null! == $ this- & gt; conn- & gt; lastInsertid ()) { $ ini ->insertId = $this->conn->lastInsertId(); } $this->num = $rum;//返回受影响的记录}
$this->num = $rum;//返回受影响的记录
的记录
//获取单条查询信息 public function fetch ($sql );pertanyaan ($sql)->fetch(PDO::FETCH_ASSOC);
}
public function fetchALL($sql){
return $this->conn->query($sql)->fetch( PDO::FETCH_ASSOC);
}
}