5

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

mysql_query("SET NAMES 'utf8'");

throws:

Warning: mysql_query() [function.mysql-query]: Access denied for user '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);
4

4 回答 4

9

不要混合使用mysql_*andmysqli_*函数。代替

mysql_query("SET NAMES 'utf8'");

利用

$dbc->set_charset('utf8');
于 2013-07-22T11:49:30.817 回答
2

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

所以使用mysqli_query来执行查询。

于 2013-07-22T11:50:15.263 回答
0

尝试这样的事情:

$dbc = mysql_connect ('localhost', 'user', 'pword');
mysql_select_db('test1',$dbc);
mysql_query('SET NAMES "utf8"',$dbc);
于 2015-01-08T21:43:45.613 回答
-2

设置php fileUTf-8似乎工作。

于 2013-08-30T11:56:37.487 回答