hello all
i've done a class for Database ( mysql ) beta 1
i'll develop it
here is the class:

<?php
/**
 * MySQL Class 0.1
 *
 * @author        Odai
 * @copyright        2011
 * @license        GNU General Public License 3 (http://www.gnu.org/licenses/)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details:
 * http://www.gnu.org/licenses/
 *
 */
 class DB{
    /**
    * $DB is an array of 3 @params
    */
    public function  __construct($connection) {
        $this->connect = mysql_connect($connection['host'], $connection['user'], $connection['pass']);
        /**
        * if there's an error on the connection
        */
        if (mysql_error()==true) {
            /**
            * show the error
            */
            die("<h1>error in data:</h1> \n". mysql_error());
            exit;
        }
        else{
            return $this->connect;
        }
    }
    /**
    * function for select the database
    */
    public function select_db($datatbase){
        $this->select=mysql_select_db($datatbase);
        /**
        * if the database is unknown
        */
        if (mysql_error()==true) {
            /**
            * show the error
            */
            die("<h1>error in data:</h1> \n". mysql_error());
            exit;
        }
        else{
            return $this->select;
        }
    }
    /**
    * function for select the table
    */
    public function select_table($table,$field){
        $this->query=mysql_query("SELECT ".$field." FROM ".$table);
        /**
        * if there's an error
        */  
if (mysql_error()==true) { /** * show the error */ die("<h1>error in data:</h1> \n". mysql_error()); exit; } else{ return $this->query; } } /** * function for extract the value */ public function extract(){ while($Row = mysql_fetch_object($this->query)){ return $Row; } } /** * function for update colmun */ public function update($table,$field,$value,$wherc,$c){ $this->updae = mysql_query("UPDATE ".$table." SET $field = $value WHERE $wherc = $c");
/** * if there's an error */
if (mysql_error()==true) { /** * show the error */ die("<h1>error in data:</h1> \n". mysql_error()); exit; } else{ return $this->update; } } /** * function for delete */ public function delete($table,$wherc,$c){ $this->delete=mysql_query("DELETE FROM ".$table." WHERE $wherc = $c"); /** * if there's an error */ if (mysql_error()==true) { /** * show the error */ die("<h1>error in data:</h1> \n". mysql_error()); exit; } else{ return $this->delete; } } function __destruct(){ mysql_close(); } } /** * End Of tha class */ ?>

uses

<?
/**
* @uses
$config = array();
$config['host']="localhost";
$config['user']="root";
$config['pass']="root";
$n=new DB($config);
$n->select_db("Notepad");
$n->select_table("daftar","*");
echo $n->extract()->name;
$n->update("example","colmun","new value","wherecolmun","old value");
$n->delete("example","colmun","value");
*/
?>

and thanks 🙂

    I didn't really go over it in detail, but one thought that pops up immediately: if you are going to use PHP5-style OOP (which is a good thing) why not use the MySQLi functionality instead of the older MySQL functions? For that matter, you might be able simply to extend the MySQLi class and add your desired functionality to it.

      Write a Reply...