Jump to content

I am getting an database charset error


co.ador

Recommended Posts

This is the error

 

Setting database encoding failed:Can't initialize character set utf-8 (path: C:\mysql\\share\charsets\)

 

How can I change the charset so it can be compatible?

 

<?php  $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if(!$connection){
die("Database connection failed:" . mysql_error());
}
//mysql_set_charset('utf8',$connection); 

if (!mysql_set_charset('utf-8', $connection)) {
die('Setting database encoding failed:' . mysql_error());
}

$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());
}?>

 

The code above is the connection to the database and i have set it to die if there is not mysql_set_charset to utf8:

 

<?php 
if (!mysql_set_charset('utf-8', $connection)) {
die('Setting database encoding failed:' . mysql_error());
}?>

 

How can I set to utf8?

what I can see is that in the folders share the charcterset utf8.xml is not in there. that means I will have to download it and put it in there?

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/185386-i-am-getting-an-database-charset-error/
Share on other sites

I have switch around the select_db and the charset  like this

 

<?php 
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if(!$connection){
die("Database connection failed:" . mysql_error());
}
//mysql_set_charset('utf8',$connection); 

$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());
}

if (!mysql_set_charset('utf-8', $connection)) {
die('Setting database encoding failed:' . mysql_error());
}
?>

 

but stil threw the same error...

 

Setting database encoding failed:Can't initialize character set utf-8 (path: C:\mysql\\share\charsets\)

It seems to possibly something with how your MySQL is setup as: C:\mysql\\share\charsets\ is not a valid path (Unless you can type that in Windows Explorer and browse to it).

 

I would look into your MySQL setup and possibly do a re-install of MySQL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.