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

  1. <?php
  2.  
  3. $DB_NAME = 'dbname';
  4. $DB_HOST = 'localhost';
  5. $DB_USER = 'dbuser';
  6. $DB_PASS = 'dbpass';
  7.  
  8. $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  9. 	if (mysqli_connect_errno()) {
  10. 		printf("Koneksi gagal: %s\n", mysqli_connect_error());
  11. 		exit();
  12. 	}
  13. 	mysqli_close($mysqli);
  14.  
  15. ?>

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.

Join the Conversation

3 Comments

Your email address will not be published. Required fields are marked *

  1. 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

  2. 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();
    }

    }
    ?>