jscript and mysql with utf-8

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garbmail10
    New Member
    • May 2009
    • 17

    jscript and mysql with utf-8

    hallo to everyone

    I'm trying to convert an older vbscript script to jscript.
    This has to run on windows script host (not any html).

    After i've done all the work i realised that when i insert data utf-8 coded into the mysql table, they are not stored correctly.

    The mysql database is the same one working with vbscript.

    Any ideas appreciated
    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you post your code. JavaScript cannot access a database, but if you're using JScript/ActiveX, you can.

    Comment

    • garbmail10
      New Member
      • May 2009
      • 17

      #3
      Thanks for replying

      I forgot to write it before, yes i use ActiveX :
      Code:
      MySql_ConnectString = "Driver={MySQL ODBC 3.51 driver};uid=root;pwd=;option=131242;database=aaa" ;
      
        var dbconn = new ActiveXObject("ADODB.Connection") ;
        dbconn.Open ( MySql_ConnectString );
        dbconn.execute ('insert into nnnn (site,site_title,site_url) values("' +Root_URL+ '" , "' + Titleutf8 + '" , "' +URL_found +'" );' );
      Thanks again
      Last edited by Frinavale; May 25 '09, 03:16 PM. Reason: Added code tags. Please post code in [code] [/code] tags.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        ActiveX is not my area of expertise, but I can offer you pointers which can hopefully help you to solve this problem. MySQL defaults to latin1, so see if there's a method that you can use to set the charset to UTF-8. What difference is there between the JScript and vbscript code in terms of the database connection/SQL code?

        Comment

        • garbmail10
          New Member
          • May 2009
          • 17

          #5
          jscript and mysql with utf-8

          hallo to everyone

          I'm trying to convert an older vbscript script to jscript.
          This has to run on windows script host (not any html).

          After i've done all the work i realised that when i insert data utf-8 coded into the mysql table, they are not stored correctly.
          I'm using ActiveX:

          Code:
          MySql_ConnectString = "Driver={MySQL ODBC 3.51 driver};uid=root;pwd=;option=131242;database=aaa" ;
          var dbconn = new ActiveXObject("ADODB.Connection") ;
          
          //## Add to MySql
          dbconn.Open ( MySql_ConnectString );
          dbconn.execute ('insert into nnnn ( field1 , title , field3 ) values("test1" , "Α" , "test3" );' );
          
          //## ReadBack From MySql
          var dbRS = new ActiveXObject("ADODB.Recordset") ;
          var adOpenForwardOnly=0,  adLockReadOnly=1 ;
          dbRS.Open ( 'field1 , title , field3 from nnnn ;'   ,dbconn ,adOpenForwardOnly ,adLockReadOnly );
          The mysql database is the same one working with vbscript.

          for example, when i'm trying to store greek capital alpha ( Α ) witch is:
          unicode 913 (0x391) ,
          after converting to utf-8 goes: 206, 145 ( 0xCE, 0x91 ),
          but after inserting to MySql and read it back is gives: 73, 63 (0x49, 0x3F)

          Any ideas appreciated
          Thanks in advance.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            merged threads since both of them cover the same problem.

            regards,
            MOD

            Comment

            • garbmail10
              New Member
              • May 2009
              • 17

              #7
              thanks acoder for replying.

              the MySql db has been created for utf8 (and it worked fine with vbs).
              So what you say is exactly the point: " What difference is there between the JScript and vbscript code in terms of the database connection/SQL code ".

              I added charset=UTF8; at MySql_ConnectSt ring but the problem persists.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                I'll have to get a MySQL expert to look at this for you.

                Is there any reason why you're changing from vbscript to jscript when both would only work in IE anyway?

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  it seems the OP just needs it to run with the WSH ... so not in a browser at all?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Ah, right, I missed that. However, WSH works with vbscript as well as JScript (or another language), so is there a reason why you must change to JScript?

                    Comment

                    • garbmail10
                      New Member
                      • May 2009
                      • 17

                      #11
                      yes i'm using it under wsh and i'm converting it to jscript so to be easy to convert to java.

                      Comment

                      • Denburt
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1356

                        #12
                        I am not quite an expert with MySql however a quick search informed me (I could be mistaken) that you can use different character sets depending on the language you are using.
                        I found an interesting article which will probably help you resolve this issue in the MySQL references. The article explains how to set up MySQL for utf8 and or set your server startup to utilize the utf8 as default.

                        I hope this helps.

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          Originally posted by garbmail10
                          yes i'm using it under wsh and i'm converting it to jscript so to be easy to convert to java.
                          hmmmm ... i just wonder about that. what does JScript have that a conversion to Java should be easier with that?

                          kind regards

                          Comment

                          • Atli
                            Recognized Expert Expert
                            • Nov 2006
                            • 5062

                            #14
                            Hi.

                            MySQL can be set up to use different charsets on everything down to individual columns.
                            But seeing as your first script successfully saved the UTF-8 chars in the same database that your second one is failing to use, my guess is that the database itself is working fine, but that your script is failing to provide it properly encoded characters.

                            Not knowing the first thing about ActiveX, or whatever script languages that thing uses; I would start looking at the query string.
                            Can it be that the string is encoded incorrectly, and that you need to specifically mark it as UTF-8 before sending it? (I've had that problem with PHP)
                            Or does the connection itself need to be configured somehow to allow it to transfer UTF-8?

                            Maybe you just need to save the script file UTF-8 encoded? (Wishful thinking :P)

                            I'm just guessing here...

                            Comment

                            • garbmail10
                              New Member
                              • May 2009
                              • 17

                              #15
                              Thanks again for your kind will to help.

                              Atli by sying "specifical ly mark the string as UTF-8 before sending it" you mean the 3 byte utf8 header ? (0xEF,0xBB,0xBF ). Maybe you have a point. My utf8 string as i check is headerless witch worked ok with vbs but maybe not with jscript. I'll check it out and let you know.

                              (For your info the script file UTF-8 encoded doesn't even run under wsh)

                              Gits the easier point is that i've never used java or jscript before so i had to learn it and starting with jscript i think is easier.

                              Thanks guys

                              Comment

                              Working...