473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.
May 25 '09 #1
18 4366
acoder
16,027 Expert Mod 8TB
Can you post your code. JavaScript cannot access a database, but if you're using JScript/ActiveX, you can.
May 25 '09 #2
Thanks for replying

I forgot to write it before, yes i use ActiveX :
Expand|Select|Wrap|Line Numbers
  1. MySql_ConnectString = "Driver={MySQL ODBC 3.51 driver};uid=root;pwd=;option=131242;database=aaa" ;
  2.  
  3.   var dbconn = new ActiveXObject("ADODB.Connection") ;
  4.   dbconn.Open ( MySql_ConnectString );
  5.   dbconn.execute ('insert into nnnn (site,site_title,site_url) values("' +Root_URL+ '" , "' + Titleutf8 + '" , "' +URL_found +'" );' );
Thanks again
May 25 '09 #3
acoder
16,027 Expert Mod 8TB
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?
May 26 '09 #4
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:

Expand|Select|Wrap|Line Numbers
  1. MySql_ConnectString = "Driver={MySQL ODBC 3.51 driver};uid=root;pwd=;option=131242;database=aaa" ;
  2. var dbconn = new ActiveXObject("ADODB.Connection") ;
  3.  
  4. //## Add to MySql
  5. dbconn.Open ( MySql_ConnectString );
  6. dbconn.execute ('insert into nnnn ( field1 , title , field3 ) values("test1" , "Α" , "test3" );' );
  7.  
  8. //## ReadBack From MySql
  9. var dbRS = new ActiveXObject("ADODB.Recordset") ;
  10. var adOpenForwardOnly=0,  adLockReadOnly=1 ;
  11. dbRS.Open ( 'field1 , title , field3 from nnnn ;'   ,dbconn ,adOpenForwardOnly ,adLockReadOnly );
  12.  
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.
May 26 '09 #5
gits
5,390 Expert Mod 4TB
merged threads since both of them cover the same problem.

regards,
MOD
May 26 '09 #6
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_ConnectString but the problem persists.
May 26 '09 #7
acoder
16,027 Expert Mod 8TB
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?
May 27 '09 #8
gits
5,390 Expert Mod 4TB
it seems the OP just needs it to run with the WSH ... so not in a browser at all?
May 27 '09 #9
acoder
16,027 Expert Mod 8TB
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?
May 27 '09 #10
yes i'm using it under wsh and i'm converting it to jscript so to be easy to convert to java.
May 27 '09 #11
Denburt
1,356 Expert 1GB
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.
http://dev.mysql.com/doc/refman/5.0/...lications.html
I hope this helps.
May 27 '09 #12
gits
5,390 Expert Mod 4TB
@garbmail10
hmmmm ... i just wonder about that. what does JScript have that a conversion to Java should be easier with that?

kind regards
May 27 '09 #13
Atli
5,058 Expert 4TB
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...
May 27 '09 #14
Thanks again for your kind will to help.

Atli by sying "specifically 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
May 28 '09 #15
gits
5,390 Expert Mod 4TB
@garbmail10
hmmmm ... you might do so but there isn't that much common between JavaScript the dialect MS JScript and JAVA ... the benefit you will get out of that current rewrite will be to have some JScript learned ... but to convert it to JAVA will be nearly different as it would have been from VBScript ... but of course it is always good to learn new things ;)

kind regards
May 28 '09 #16
nope, utf8 header is needed only at saved files.
fiinaly i'm gonna store data to mysql as unicode and just convert them to utf-8 at the php part.
Is there any reliable php routine to convert unicode to utf-8 ?
May 28 '09 #17
gits
5,390 Expert Mod 4TB
you may have a look at this

kind regards
May 28 '09 #18
mission accomplished

thanks acoder gits Denburt Atli
May 29 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Aditya Ivaturi | last post by:
We have a CMS which is written is based on php & mysql. Recently we received a request to support multiple languages so that sites in that particular laguage can be created. I did some search on...
5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
0
by: Stian Grytøyr | last post by:
When I submit a query containing a UTF-8 representation (hex value 0xC48D) of the Unicode character &#x010D (lowercase c with caron) to the MySQL server using mysql_query, sniffing the network...
6
by: Jonas Meurer | last post by:
hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8...
4
by: Harag | last post by:
Hi All I currently thinking of converting from my little knowledge of VBscript to jScript ASP. With this in mind I'm looking at my current code to see how it will convert over to Jscript. ...
1
by: Peter King | last post by:
I have a site on a server using ASP and MySQL 3.23.54 (Cobalt Raq server) I have been asked to convert the site to Unicode and need to know: 1) If MySQL 3.23 supports unicode 2) How do I...
2
by: Kevin Laurence | last post by:
Can anyone advise me on the use of UTF-8 in PHP and MySQL? What is the best approach? I would prefer to store HTML extended characters in the database as UTF-8, but I can only get the HTML to...
2
by: tunk | last post by:
I dont know where to start my question so let me tell you my story :) The ASP that cause me trouble is running on IIS that set ASP default language to JScript instead of VBScript. This ASP page...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.