Wednesday, 22 August 2007

PHP 5, OOP

PHP 5 now support Object Oriented Programming, in this chapter, i will show you an example :
------------------
/* conf.php */
$host="localhost";
$user="root";
$pass="samsonasik";
$db="mydb";
?>
-----------------
/* mysqldb.class.php */

class myqldb{
var $host,$user,$pass,$db,$id;
function connect(){
include "conf.php";
$this->host=$host;
$this->user=$user;
$this->pass=$pass;
return mysql_connect($this->host,$this->user,$this->pass);
}

function getdb(){
include "conf.php";
$this->db=$db;
return mysql_select_db($this->db);
}

function deleteid($id){
return mysql_query("delete from book where id='$id'");
}
}
?>
-----------------------------------
/* deleteid.php */
include "mysqldb.class.php";
$del=new mysqldb();
$del->connect();
$del->getdb();
$del->deleteid("001");
?>

it's so simple ???

No comments: