Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.