duan32342 2018-05-03 01:30
浏览 47

中文字符只是不会出现在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 2018-05-03 02:23
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算