Skip navigation


Lumayan hasil bebersih folder tugas progin tahun lalu. Ada class wrapper buat koneksi database MySQL😛

<?php

class database {
    var $database_host;
    var $database_user;
    var $database_pswd;
    var $database_name;
    var $database_link;
    var $last_result;

    function mysql($database_host, $database_user, $database_pswd, $database_name){
        $this->database_host = $database_host;
        $this->database_user = $database_user;
        $this->database_pswd = $database_pswd;
        $this->database_name = $database_name;
        $this->database_link = mysql_connect($this->database_host, $this->database_user, $this->database_pswd) or die("<strong>Could not connect to database</strong> : ".mysql_error());
        mysql_select_db($this->database_name, $this->database_link) or die("<strong>Could not select database</strong>".mysql_error());
    }

    function query($query_string){
        $result = mysql_query($query_string, $this->database_link);
        if(!$result) {
            return false;
        } else {
            return $result;
        }
    }

    function fetch_assoc($result){
        return mysql_fetch_assoc($result);
    }

    function rows_affected($result){
        return mysql_rows_affected($result);
    }    

    function num_rows($result){
        return mysql_num_rows($result);
    }
}
//end of file

well, sekarang udah ada yang namanya framework. Bener-bener menyenangkan.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: