insert greek characters in my sql database

insert greek characters in my sql database

aristidisaristidis Posts: 8Questions: 2Answers: 0
edited December 2013 in General
i m using DataTables Editor.how can i insert greek characters in my sql database.With other applications the < mysql_query("SET NAMES 'utf8'", $con); > works for me..How can I get that to work in datatable editor? How can I get that to work?please help me on this.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi,

    What you can do is use the Database class `sql` method:
    https://editor.datatables.net/docs/current/php/class-DataTables.Database.html#_sql

    So you might use:

    [code]
    $db->sql( "SET NAMES 'utf8'" );
    [/code]

    Allan
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Allan,
    The utf8 question has cropped up here more than once. Maybe it would be worth writing a commented example into the Bootstrap?
    Speaking of the Bootstrap: "// Database connection it globally available" should be *is* ;-)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited December 2013
    Thanks for posting the typo, will be fixed in the next release.

    Yes, it might be worth me putting a comment in about the UTF8 connection. I've assumed that the db, and the html page will both use the same character set, which shouldn't cause any issues, regardless of what character set is used, since Editor / DataTables don't care about the character set. I'm surprised by how often this does crop up to be honest.

    Allan
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    TBH character sets are usually a bit of a puzzle to me. My db and HTML both use utf8, but I still had to incorporate the bootstrap fix mentioned in here.
    I just noticed that my cdn use of jquery does not specify a charset:
    script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
    whereas my local requirement of dataTables does;
    script type="text/javascript" language="javascript" charset="utf-8" src="js/jquery.dataTables.min.js">

    Could that be relevant?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The Javascript should actually just assume the same character set as the host HTML page. Is that also UTF8?

    Allan
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    "Is that also UTF8?"
    Yep.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Bizzare! The only other thing I can thing of is that the link your scripting environment is using (PHP?) to connect to the db is not UTF8 and something is doing a translation along the way...

    Allan
  • aristidisaristidis Posts: 8Questions: 2Answers: 0
    thanks Allan <<$db->sql( "SET NAMES 'utf8'" );>> works fine.
This discussion has been closed.