telaga.cs.ui.ac.id

Download Report

Transcript telaga.cs.ui.ac.id

Object Oriented in PHP
<?#file: akademik.php
class Mahasiswa {
var $pstudi ;
function setPstudi($ps) {
$this->pstudi = $ps;
}
function getPstudi() {
return $this->pstudi ;
}
}
?>
<?
include (“akademik.php”) ;
$mhs1 = new Mahasiswa;
$mhs1->setPstudi('Ilmu Komputer');
print ($mhs1->getPstudi() . "<br />") ;
?>
Inheritence
<?#file: akademik.php
class Akademika {
var $nama, $ketr ;
function setNama($nm) {
$this->nama = $nm;
}
function getNama() {
return($this->nama) ;
}
}
class Mahasiswa extends Akademika {
var $pstudi ;
function setPstudi($ps) {
$this->pstudi = $ps;
}
function getPstudi() {
return $this->pstudi ;
}
}
?>
<?
include (“akademik.php”) ;
$mhs1 = new Mahasiswa;
$mhs1->setPstudi('Ilmu Komputer');
$mhs1->setNama('Asep Surungan');
print ($mhs1->getNama() . "<br />") ;
print ($mhs1->getPstudi() . "<br />") ;
?>
Abstract Function
<?#file: akademik.php
class Akademika {
var $nama ;
function setNama($nm) {
$this->nama = $nm;
}
function getNama() {
return($this->nama) ;
}
abstract function setDeskripsi($d) ;
abstract function getDeskripsi() ;
}
class Mahasiswa extends Akademika {
var $pstudi ;
function setPstudi($ps) {
$this->pstudi = $ps;
}
function getPstudi() {
return $this->pstudi ;
}
}
?>

Fatal error: Class Akademika contains 1
abstract method and must therefore be
declared abstract or implement the remaining
methods (Akademika::setDeskripsi) in
akademika.php on line 12
<?#file: akademik.php
abstract class Akademika {
var $nama ;
function setNama($nm) {
$this->nama = $nm;
}
function getNama() {
return($this->nama) ;
}
abstract function setDeskripsi($d) ;
abstract function getDeskripsi() ;
}
class Mahasiswa extends Akademika {
var $pstudi, $ketr ;
function setPstudi($ps) {
$this->pstudi = $ps;
}
function getPstudi() {
return $this->pstudi ;
}
function setDeskripsi($d) { $ketr = $d ; }
function getDeskripsi() { return $this->ketr; }
}
?>
Adodb






Database Abstraction
Well matured library: It has been continuously
developed since 2000.
Very good performance-monitoring library.
Easy to use caching functions helping to increase
performance of high traffic sites.
Full database session support: Allows for easy
creation of user systems.
Layered code makes ADODB a very fast library and
only adds a slight overhead if performing common
tasks.
Using Adodb

require('adodb.inc.php');

$dsn = 'mysql://username:pwd@localhost/dbname?persist';

$db = ADONewConnection($dsn); # no need for Connect()

$sql = "SELECT Nama FROM MHS” ;

$cset = $db->Execute($sql) ;

While (! $cset->EOF) {




}
$arr = $cset->FetchRow() ;
$nama = $arr[0] ;
Print $name. “<br />” ;