<?php
class odbc{
public $hostname;
public $username;
public $password;
public $database;
private $connection;
private $query;
private $res;
/*** default constructor รข�� ***/
public function __construct() {
$this->hostname = '';
$this->username = '';
$this->password = '';
$this->database = '';
}
/** **/
public function __set($nama, $nilai) {
switch ($nama) {
case "hostname" : $this->hostname = $nilai; break;
case "username" : $this->username = $nilai; break;
case "password" : $this->password = $nilai; break;
case "database" : $this->database = $nilai; break;
default:
throw new Exception('Error...');
}
}
/** adeh.. nie function connect dlm yg akan dipanggil oleh app **/
private function odbc_connect_func() {
if($this->connection = odbc_pconnect($this->hostname,$this->username,$this->password) ) /* $this->database akan guna nnti la yer.. */
return true;
else
return false;
}
public function connect() {
if ($this->odbc_connect_func() === false) {
throw new Exception('Error...!');
}
}
public function query($getQuery) {
if(!$this->res = odbc_exec($this->connection,$getQuery)) {
throw new Exception("Query gagal..".odbc_error());
return false;
}
else { return true; }
}
public function fetchall() {
$ret = array();
while($row = odbc_fetch_array($this->res)) {
$ret[] = $row;
}
return $ret;
}
public function numrow(){
$ret = 0;
}
}
?>
Nah, seperti itulah class nya. (download lengkap di sini) kemudian bagaimana cara menggunakannya akan saya bahas pada postingan selanjutnya... terimakasih.
No comments:
Post a Comment