| mohon bantuan nya master" php,, kenapa protected di awal function di bawah error ya ????? coding program : <?php
include "../koneksi.php"; /** * Method untuk menyimpan data kedalam database * string $tabel * array $data : $key = kolom dan $value = data yang akan disimpan. * @return boolean true : jika berhasil, false gagal *protected dag ttidak terbaca awal function */ protected function simpan($tabel, $data)//protected tidak terbaca { $str = "INSERT INTO %s %s VALUES (%s)"; $kolom = array_keys($data); $kolom = "(" . implode(',', $kolom) . ")"; foreach ($data as $value) { $nilai[] = "'$value'"; } $nilai = implode(',', $nilai); $qry = sprintf($str, $tabel, $kolom, $nilai); return $this->execute($qry); }
/** * Method untuk melakukan query SELECT * string $limit : off,len : off : awal indeks yang dibaca, len : banyak data * @return array[array] : array 2 dimensi */ protected function select($tabel, $kolom="*", $where="", $limit="", $order="") {
if ($kolom != "*") { $kolom = implode(',', $kolom); } if ($where != "") { $where = "WHERE $where"; } if ($limit != "") { $limit = "OFFSET " . str_replace(',', ' LIMIT ', $limit); } if ($order != "") { $order = "ORDER BY $order DESC"; } $qry = "SELECT $kolom FROM $tabel $where $order $limit "; $hasil = $this->execute($qry); # echo $qry; while ($baris = @mysql_fetch_assoc($hasil)) { $data[] = $baris; } return $data; }
/** * mengubah data */ protected function update($tabel, $data, $where) { foreach ($data as $key => $value) { $set[] = "$key='$value'"; } $set = implode(',', $set); $str = "UPDATE $tabel SET $set WHERE $where"; return $this->execute($str); }
/** * menghapus data */ protected function delete($tabel, $where="") { if ($where != "") { $where = " WHERE " . $where; } $str = "DELETE FROM $tabel $where"; return $this->execute($str); }
/** * Mengeksekusi perintah SQL */ protected function execute($string, $data=false) { if ($data) { $hasil = mysql_query($string); while ($baris = mysql_fetch_assoc($hasil)) { $d[] = $baris; } return $d; } return mysql_query($string); }
?> |
Tidak ada komentar:
Posting Komentar