Postingan lainnya
Fix error sql connection
Saya menggunakan versi php 5.1 (lama), sehingga muncul warning seperti ini. Adakah yang tau masalahnya dimana?
<?php
class database
{
var $koneksi ;
var $selectDb;
var $query ;
var $result ;
var $row;
var $jumlah ;
function database()
{
$nameSer = "localhost"; //Nama Host
$username = "root"; //username Host
$pass = ""; //Passwrod Host
$dbname = "db_androsalesv2"; //Database Name
$koneksi = mysqli_connect($nameSer,$username,$pass)or die('error DB : '.mysqli_errno());
$this->selectDb = mysqli_select_db($dbname,$koneksi);
if ( !$this->selectDb )
{
echo "gagal";
}
}
function query($query)//fungsi query
{
$this->result = mysqli_query($koneksi,$query);
}
function tutup()//fungsi query
{
mysqli_close();
}
function tampilkan()//fungsi menampilkan data
{
$this->row = mysqli_fetch_array($this->result);
return $this->row;
}
function view()//fungsi menampilkan data
{
$this->row = mysqli_fetch_object($this->result);
return $this->row;
}
function getJumlah()//fungsi menampilkan jumlah data
{
$this->jumlah = mysqli_num_rows($this->result);
return $this->jumlah;
}
function get($table)//fungsi select
{
$this->result = mysqli_query("SELECT * FROM ".$table);
}
function getJumlahFromTable($table)
{
$this->get($table);
return $this->getJumlah();
}
function insert( $database , $data)//fungsi insert
{
$row = array();
$nilai = array();
foreach ( $data as $kolom =>$value )
{
$row[] = $kolom;
$nilai[] = "'".$value."'";
}
$this->result = $this->query("INSERT INTO ". $database ."(". implode(',' ,$row) .")
VALUES (". implode(',' , $nilai) .")");
}
function update($table , $data , $where)//fungsi update
{
foreach ( $data as $kolom => $row )
{
$set[]= $kolom."='".$row."'" ;
}
$set = implode(',',$set);
$query = "UPDATE ".$table." SET ".$set." WHERE ".$where ;
$this->query($query);
}
function delete($table , $where)//fungsi delete
{
$this->query("DELETE FROM ".$table." WHERE ".$where);
}
}
?>
0
3 Jawaban:
Coba variable nya jangan pake var tapi biasa aja. $koneksi = "";
Atau pake const
0
coba pelajari lagi tentang $variabel dan $this-variable.
dan coba perhatikan penggunaan mysqli_select_db, harusnya koneksi dulu baru nama databasenya
<pre> mysqli_select_db($koneksi,$namaDatabase) </pre>
Pelan2 diujinya biar gampang nemuin errornya :)
https://www.php.net/manual/en/mysqli.select-db.php
1