doukuang8166 2017-02-16 14:58
浏览 32
已采纳

无法更改PHP MySQLi连接的Charset

Why is it when connecting with a mysql client on my server I can run "CHARSET utf8mb4" and have the connection's charset changed, but when I try and execute that same statement via mysqli it gives me the following error:

ERROR SQL error in "charset utf8mb4"; You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'charset utf8mb4' at line 1

  • 写回答

2条回答 默认 最新

  • dongtiannan0367 2017-02-16 15:06
    关注

    As far as I know, MySQL Server does not have any charset command either. You specify the charset with SET NAMES, which is a short-cut to set several related variables (all of which can be set with the SET command anyway).

    You're probably confused with the command of the official command-line client:

    mysql> \h
    
    For information about MySQL products and services, visit:
       http://www.mysql.com/
    For developer information, including the MySQL Reference Manual, visit:
       http://dev.mysql.com/
    To buy MySQL Enterprise support, training, or other products, visit:
       https://shop.mysql.com/
    
    List of all MySQL commands:
    Note that all text commands must be first on line and end with ';'
    ?         (\?) Synonym for `help'.
    clear     (\c) Clear the current input statement.
    connect   () Reconnect to the server. Optional arguments are db and host.
    delimiter (\d) Set statement delimiter.
    ego       (\G) Send command to mysql server, display result vertically.
    exit      (\q) Exit mysql. Same as quit.
    go        (\g) Send command to mysql server.
    help      (\h) Display this help.
    notee     (\t) Don't write into outfile.
    print     (\p) Print current command.
    prompt    (\R) Change your mysql prompt.
    quit      (\q) Quit mysql.
    rehash    (\#) Rebuild completion hash.
    source    (\.) Execute an SQL script file. Takes a file name as an argument.
    status    (\s) Get status information from the server.
    tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
    use       (\u) Use another database. Takes database name as argument.
    charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
    warnings  (\W) Show warnings after every statement.
    nowarning (\w) Don't show warnings after every statement.
    

    Since you are using PHP, not the command-line client, it doesn't exist.

    Of course, the mysqli way to set the encoding is mysqli::set_charset().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?