Error yang muncul di browser/debugger
Warning: mysqli::real_escape_string(): Couldn't fetch mysqli in /var/www/html/top10.php on line 85 Warning: mysqli::query(): Couldn't fetch mysqli in /var/www/html/top10.php on line 91
setelah lihat code sana sini, ternyata error tersebut karena fungsi mysqli_close, di halaman top10.php saya meng-include-kan koneksi.php yang isinya
<?php
$DB_NAME = 'dbname';
$DB_HOST = 'localhost';
$DB_USER = 'dbuser';
$DB_PASS = 'dbpass';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Koneksi gagal: %s\n", mysqli_connect_error());
exit();
}
mysqli_close($mysqli);
?>
ubah baris ke 13 sehingga menjadi
// mysqli_close($mysqli);
dengan menambah tanda //
di depan perintah PHP, sama dengan mendisable perintah tersebut.mysqli_close
saya tambahkan di top10.php.
Warning: mysqli::query(): Couldn’t fetch mysqli in /storage/ssd4/840/13211840/public_html/models/m_anggota.php on line 16
Warning: Anggota::tampil(): Couldn’t fetch mysqli in /storage/ssd4/840/13211840/public_html/models/m_anggota.php on line 16
mysqli = $conn;
}
public function tampil($id = null) {
$db = $this->mysqli->conn;
$sql = ” SELECT * FROM tb_anggota”;
if($id != null) {
$sql .= “WHERE id_agt = $id”;
}
$query = $db->query($sql) or die ($db->error);
return $query;
}
public function tambah($nm_agt, $jbt_agt, $prd_agt, $foto_agt) {
$db = $this->mysqli->conn;
$db->query(“INSERT INTO tb_anggota VALUES (”, ‘$nm_agt’, ‘$jbt_agt’, ‘$prd_agt’, ‘$foto_agt’)”) or die ($db->error);
}
public function edit($sql) {
$db = $this->mysqli->conn;
$db->query($sql) or die ($db->error);
}
public function hapus($id) {
$db = $this->mysqli->con;
$db->query(“DELETE FROM tb_anggota WHERE id_agt = ‘$id'”) or die ($db->error);
}
function __desctruct() {
$db = $this->mysqli->conn;
$db->close();
}
}
?>
Terimakasih atas informasinya. Sangat membantu dikala deadline.