Sourcecode:
<?php
class matakuliah
{
var $koneksi;
function Matakuliah() {
$this->koneksi = mysql_connect('localhost','root','');
mysql_select_db('149',$this->koneksi);
}
function getMatakuliah($kode_mk)
{
$sql = "select * from
matakuliah where kode_mk='$kode_mk'";
$result = mysql_query($sql,
$this->koneksi);
list($kode_mk, $nama_mk, $sks,
$semester, $tanggal) = mysql_fetch_array($result);
$this->kode_mk = $kode_mk;
$this->nama_mk = $nama_mk;
$this->sks = $sks;
$this->semester =
$semester;
$this->tanggal = $tanggal;
}
function addMatakuliah($data)
{
$sql = "insert into
matakuliah values
('".$data['kode_mk']."','".$data['nama_mk']."',
'".$data['sks']."','".$data['semester']."','".$data['tanggal']."')";
mysql_query($sql,
$this->koneksi);
}
}
$a = new matakuliah();
$dataku = array ( 'kode_mk'
=> 'B001',
'nama_mk' => 'Framework',
'sks' => 2,
'semester' => 5,
'tanggal' => '1999-12-12'
,
);
$a->addMatakuliah($dataku);
$a->getMatakuliah('B001');
echo "<br>Kode MK = ".$a->kode_mk;
echo "<br>Nama MK = ".$a->nama_mk;
echo "<br>SKS = "
.$a->sks;
echo "<br>Semester = " .$a->semester;
echo "<br>Tanggal = "
.$a->tanggal;
?>
|
Output:
0 komentar:
Post a Comment