duan32342
duan32342
2018-05-03 01:30

中文字符只是不会出现在php文件中

Okay i am so mad at this i ve been working on this for like hours and it still doesn't work. it still gives me ?? when ii inserted some chinese characters on the table field.

I've already tried the below from stack overflow and it still doesn't work. i really need to get this finished or else i aint gonna know what to do with php functions on figuring out the position of a character if i use the form to insert code to the database because it gives me really random characters have no idea what they are.

The below are the methods i ve already approached:

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duan33360 duan33360 3年前

    You've probably set the COLLATE for your SQL tables to utf8-unicode-ci. Don't worry about that right now, I suggest what you need to do is create a separate php file called connect.php or con.php or other such to put your connection/selection database stuff in there.

    $username = "root";
    $password = "";
    $database = "databasename";
    $server = "127.0.0.1";
    
    $connect = @mysqli_connect($server, $username, $password);
    $select = mysqli_select_db($connect, $database);
    
    mysqli_set_charset($connect, 'utf8');
    
    if(!$connect) { die("Connection failed: ".mysqli_error()); }
    if(!$select) { die("Selection failed: ".mysqli_error()); }
    

    Then put

    require("connect.php");
    

    on the top of all your php pages.

    Once you've done so, you don't even need to worry about changing the Chinese code on the SQL statements you make.

    点赞 评论 复制链接分享

相关推荐