php SET NAMES 命令因访问被拒绝而失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17786726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:27:06  来源:igfitidea点击:

SET NAMES command fails with access denied

phpmysqlunicodeutf-8

提问by snookian

I'm trying to insert an accented einto a mysql database following this example. Using this:

我正在尝试e按照此示例在 mysql 数据库中插入一个重音符号。使用这个:

mysql_query("SET NAMES 'utf8'");

throws:

抛出:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost'

警告:mysql_query() [function.mysql-query]:用户 'ODBC'@'localhost' 拒绝访问

Its not connecting to the database:

它没有连接到数据库:

DEFINE ('DB_USER', 'user');
DEFINE ('DB_PASSWORD', 'pword');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'test1');
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

采纳答案by snookian

Setting the php fileto UTf-8seemed to work.

设置php fileUTf-8似乎有效。

回答by PleaseStand

Don't mix use of the mysql_*and mysqli_*functions. Instead of

不要混合使用mysql_*mysqli_*功能。代替

mysql_query("SET NAMES 'utf8'");

use

$dbc->set_charset('utf8');

回答by Code L?ver

I think there is no problem in connection there is the the problem that you are using the mysql_queryand you are connecting with mysqli_connect.

我认为连接没有问题,是您使用的问题mysql_query和您正在连接的问题mysqli_connect

So use the mysqli_queryto execute the query.

所以使用mysqli_query来执行查询。

回答by iGzorn

try something like this:

尝试这样的事情:

$dbc = mysql_connect ('localhost', 'user', 'pword');
mysql_select_db('test1',$dbc);
mysql_query('SET NAMES "utf8"',$dbc);