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
SET NAMES command fails with access denied
提问by snookian
I'm trying to insert an accented e
into 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 file
to UTf-8
seemed to work.
设置php file
为UTf-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_query
and you are connecting with mysqli_connect
.
我认为连接没有问题,是您使用的问题mysql_query
和您正在连接的问题mysqli_connect
。
So use the mysqli_query
to 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);