How to set UTF-8 connection to MYSQL?
How to set UTF-8 connection to MYSQL?
kiki
Posts: 15Questions: 1Answers: 0
Hi , a have problem. In database value - "Větvička" . Value from "V?tvi?ka".
database set UTF-8 , table collation utf8_czech_ci
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Are you using Editor, a PDO connection, an ADO.NET connection? We'd need a lot more information that you've given in order to be able to offer any help.
Allan
Hi, mysql connection. Server-side conenction. (https://www.datatables.net/examples/server_side/simple.html) ---- Server linux, apache, php 5.3 --- thank you zbynek
http://www-pomoc.cz/_wordpress/?p=64
If it needs to pay and tell me how much.
thanks zbynek
Try adding:
At line 237 in the
ssp.class.php
file.That would force a UTF8 connection between PHP and the MySQL server, addressing any misconfigurations.
Allan
Hi,
DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7
think of me as to convert the string that is returned from the db. Something like iconv in PHP.
or as the editor in the connection configuration - option dsn
database - "users" utf8_general_ci
table - "full" MyISAM utf8_czech_ci
zbynek
Did you check to see what data was returned by the Ajax request? Did you contain an error message? Did you check the server's error logs?
Allan
Hi, if inserting line
.............. self::sql_exec( $db, 'SET NAMES utf8' ); ....................
error. If comment line - no UTF8 strings.
As I see encoding server or database?
character_set_database
character_set_server
collation_database
collation_server
There I stated "latin1_swedish_ci" - so that I can change.
setting ..... but I ............... character_set_system utf8
Thanks
zbyněk
I'm all change utf8. It's the same.
zbynek
Outside of dataTables, this is a pretty common issue when the database is stored as a latin character set, for example, but your form allows UTF-8 characters. You should either go into your database and change the character set to UTF-8 or develop a conversion routine for the longtext fields. Prior to any database insertion, I perfrom a convertUTF8toLatin1 so my character sets are at least readable by the database.
Thanks for the help.
I've got everything utf8. Yet it is not working. :(
I was put into a table manually data czech " č ř ž ě " and does not appear as well. ; (
so the problem is not that I stupidly signed data.
Thanks
zbynek
I'm afraid there isn't a huge amount of help we can offer here without access to your server. Its a server-side issue, so its difficult to say what the issue is if the normal approach didn't work.
Can you perform a normal PHP PDO
SELECT
and get UTF8 output?Allan
Allan please send e-mail kiki@seznam.cz . thanks zbynek
I should have qualified that, I'm not offering to fix your server :-). That's well beyond the scope of the free support that I offer.
I just wanted to show that really do not know why it's not working. ; (
I made a page for testing. it does not work: P
I asked what it would cost me.
http://www-pomoc.cz/_datatable/1.php
zbynek
Try to insert into the table "ěščřžýáíéúů ĚŠČŘŽÝÁÍÉÚŮ"
if you do the work, I find fault with them. I do not believe that, in a configuration that is available it will be right.
The local solution is the best I've found. If it does not work otherwise, I'll keep looking on the Internet.
Thank you for your help
zbynek
My suggestion would be to try and create a trivial PHP file which uses a PDO connection to read data from the database. A simple
SELECT...
would do and print the data out. That way you can check to see if you can make a PDO connection that will work with the character encoding you want.Allan
Hi.
my connect
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8");
I suggested using PDO and making a SELECT query. Instead you appear to have using mysqli. That's fine, you can do that and update the server-side processing script to use mysqli rather than PDO if you prefer.
Hi,
I do not understand what you mean.
I described my simple PDO me and everything works as it should.
how to add set_charset on scripts?
thanks
zbynek
Your example doesn't use PDO at all. It uses
mysqli
- as you can see by the use of themysqli
class.This page shows an example of using PDO (first link from a simple Google search). It even shows how to set the charset.
I would suggest testing it that way before adding the complexity of the server-side processing script.
Allan
OK. Thank you for your help.
zbynek
I've the same problem, i checked in a php file when using charset, that shows correct:
$db = new PDO('mysql:host=localhost;dbname=test;charset=utf8mb4', 'root', '123');
it means datatables by default didn't set utf8 ? ;-)
kiki follow this:
go to ssp.class.php file --> line 388 edit that line to:
array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" )
save the file and works fine :-)
THANK'S bashirnoori ALL SOLVED!!!