Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SET NAMES command fails with access denied

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);
like image 217
snookian Avatar asked Jul 22 '13 11:07

snookian


2 Answers

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

mysql_query("SET NAMES 'utf8'");

use

$dbc->set_charset('utf8');
like image 118
PleaseStand Avatar answered Nov 18 '22 20:11

PleaseStand


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.

So use the mysqli_query to execute the query.

like image 2
Code Lღver Avatar answered Nov 18 '22 21:11

Code Lღver