使用php OPP在mysqli中插入Bangla

时间:2018-05-30 10:48:01

标签: php mysqli

我想使用bangla模型OPP插入php。在数据库字段中,我设置了 utf8_general_ci ,但我的代码需要进行哪些更改,我无法弄清楚。这是我的数据库类。

 <?php
// define Database class
class Database{
    public $host = DB_HOST;
    public $username = DB_USER;
    public $password = DB_PASS;
    public $db_name = DB_NAME;

    public $link;
    public $error;


    /*
     * constructor 
     */
    public function __construct(){
        $this->connect();
    }

    /*
     * Database connect function
     */
    private function connect(){
        $this->link = new mysqli($this->host,$this->username,$this->password,$this->db_name);
        // mysqli_query($conn,'SET CHARACTER SET utf8');
       //mysqli_query($conn,"SET SESSION collation_connection ='utf8_general_ci'");

        if(!$this->link){
            $this->error = "connection Failed : ".$this->link->connect_error;
            return false;
        }
    }



    /*
     * Select
     */
    public function select($query){
        $result = $this->link->query($query) or die($this->link->error.__LINE__);

        if($result->num_rows > 0){
            return $result;
        }
        else{
            return false;
        }
    }


    /*
     * insert
     */
    public function insert($query){
        $insert_row = $this->link->query($query) or die($this->link->error.__LINE__);

        if($insert_row){
        header("location: index.php?msg=".".urlencode('inserted').");
        }
        else{
            die('error : ('.$this->link->error .')'.$this->link->error);
        }
    }

    /*
     * update
     */
    public function update($query){
        $update_row = $this->link->query($query) or die($this->link->error.__LINE__);

        if($update_row){
            header("location: index.php?msg=".".urlencode('updated').");
        }
        else{
            die('error : ('.$this->link->error .')'.$this->link->error);
        }
    }

    /*
     * Delete
     */
    public function delete($query){
        $delete_row = $this->link->query($query) or die($this->link->error.__LINE__);

        if($delete_row){
            header("location: index.php?msg=".".urlencode('Deleted').");
        }
        else{
            die('error : ('.$this->link->error .')'.$this->link->error);
        }
    }

}
     ?>

我谷歌并找到了对程序模型有用的方法,但没有理解它如何与OPP模型一起使用。 建议请!

0 个答案:

没有答案