php odbc class version 1.0

powered by php
<?php
/*****************
Database Class for odbc use;
tested on windows xp, windows server 2003(yg nie susah skit sbb nak kena configure server permission utk read file) and windows 2000
generally speaking, nie kira nya untuk windows jer la.. sbb dlm linux sy tak tahu.. hahahahaha
@author : Mohd Hafeez
@company: Freelancer bukan Mitsubishi Lancer Evo xii
@copyright (c) october 2007 https://myapit.wordpress.com
@version 1.0
**********************/

class odbc{
public $hostname;
public $username;
public $password;
public $database;

private $connection;
private $query;
private $res;

/*** default constructor — cam java lak ***/
public function __construct() {
$this->hostname = ”;
$this->username = ”;
$this->password = ”;
$this->database =”;
}
/** hm,mmm… nie default set plak **/
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(‘Maaf la.. sila ikut contoh yg diberi.. salah nie.’);
}
}

/** adeh.. nie function connect dlm yg akan dipanggil oleh app **/
/** lor.. dah x larat nak komen dah nie **/
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(‘Maap.. latabase tarak bleh connect wooooo!’);
}
}

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(); /* cuba teka .. apakah ini */
while($row = odbc_fetch_array($this->res)) {
$ret[] = $row;
}
return $ret;
}

public function numrow();
$ret = 0;

}

/*********************
Contoh Penggunaan: 1
try {
include”odbc_class.php”;

$db = new odbc();
$db->hostname = ‘test’;
$db->username = ‘apit’;
$db->password = ‘apit123’;
$db->database = ”;
$dbcon = $db->connect();
$db->query(“SELECT * FROM tblLogin”);
foreach($db->fetchall() as $aResult) {
echo “Login Name: “. $aResult[‘login_name’].'<br />’;
}

}
catch (Exception $oError) {

echo ‘Message: ‘.$oError->getMessage();

}

Contoh Penggunaan: 2

include ‘odbc_class.php’;
$db = new odbc();
$db->hostname = ‘test’;
$db->username = ‘apit’;
$db->password = ‘apit123’;
$db->database = ”;
$dbcon = $db->connect();

$db->query(“SELECT * FROM tblLogin”);
foreach($db->fetchall() as $aResult) {
echo “Login Name: “. $aResult[‘login_name’].'<br />’;
}

$db-query …. blalblablablabla
***************************************/
?>
Just Copy & paste…

Under GNU License ????

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s