关于utf8字符显示的phpmyadmin

时间:2018-08-13 22:27:52

标签: php phpmyadmin character-encoding

我在utf8字符显示方面遇到问题;有些部分显示如下:????????

phpmyadmin中的所有unicode均为utf8通用ci,因此我发现应该在我的lib.php文件中添加以下代码:

mysql_query(“SET CHARACTER SET utf8″);

但是我应该在哪里放置这段代码?

这是我的 lib.php

<?php
Class Database{
    public $host   = DB_HOST;
    public $user   = DB_USER;
    public $pass   = DB_PASS;
    public $dbname = DB_NAME;


    public $link;
    public $error;

    public function __construct(){
        $this->connectDB();
    }

    private function connectDB(){
    $this->link = new mysqli($this->host, $this->user, $this->pass, $this->dbname);
    if(!$this->link){
        $this->error ="Connection fail".$this->link->connect_error;
        return false;
    }
 }

    // Select or Read data

    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 data
    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('Data Inserted successfully.'));
        exit();
    } else {
        die("Error :(".$this->link->errno.")".$this->link->error);
    }
  }

    // Update data
    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('Data Updated successfully.'));
        exit();
    } else {
        die("Error :(".$this->link->errno.")".$this->link->error);
    }
  }

  // Delete data
   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('Data Deleted successfully.'));
        exit();
    } else {
        die("Error :(".$this->link->errno.")".$this->link->error);
    }
  }



}

我读了最相关的问题,只是想知道应该在哪里添加代码。

0 个答案:

没有答案