How to set UTF-8 connection to MYSQL?

How to set UTF-8 connection to MYSQL?

kikikiki Posts: 15Questions: 1Answers: 0
edited January 2016 in Free community support

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

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    Hi, mysql connection. Server-side conenction. (https://www.datatables.net/examples/server_side/simple.html) ---- Server linux, apache, php 5.3 --- thank you zbynek

  • kikikiki Posts: 15Questions: 1Answers: 0
  • kikikiki Posts: 15Questions: 1Answers: 0

    If it needs to pay and tell me how much.
    thanks zbynek

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Try adding:

    self::sql_exec( $db, 'SET NAMES utf8' );
    

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    Hi,

        $db = self::db( $conn );
        self::sql_exec( $db, 'SET NAMES utf8' );
        // Build the SQL query string from the request
    

    DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7

  • kikikiki Posts: 15Questions: 1Answers: 0
    edited January 2016

    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

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    I'm all change utf8. It's the same.

    zbynek

  • glendersonglenderson Posts: 231Questions: 11Answers: 29
    edited January 2016

    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.

  • kikikiki Posts: 15Questions: 1Answers: 0

    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

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    Allan please send e-mail kiki@seznam.cz . thanks zbynek

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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.

  • kikikiki Posts: 15Questions: 1Answers: 0

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    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

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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

  • kikikiki Posts: 15Questions: 1Answers: 0

    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");

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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.

  • kikikiki Posts: 15Questions: 1Answers: 0

    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

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Your example doesn't use PDO at all. It uses mysqli - as you can see by the use of the mysqli 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

  • kikikiki Posts: 15Questions: 1Answers: 0

    OK. Thank you for your help.
    zbynek

  • bashirnooribashirnoori Posts: 2Questions: 0Answers: 0

    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 ? ;-)

  • bashirnooribashirnoori Posts: 2Questions: 0Answers: 0

    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 :-)

  • PLAGAPLAGA Posts: 1Questions: 0Answers: 0

    THANK'S bashirnoori ALL SOLVED!!!

This discussion has been closed.