Hi there,
I have a MYSQL database which needs to be accessed by both PHP and MySQL scripts, this works fine in most cases, but some "special" characters e.g. double quotes, apostrophes don't display correctly in the ASP scripts.
E.g the MySQL database is from a Drupal installation and contains a table with a field containing the text “A double quote” (the quotes are smart quotes but don't seem to dislay on stack overflow). This displays fine in a php script, but not an ASP script. I've written a simple script in both PHP and ASP to loop through the string and print the character codes here are the outputs:
PHP
“ 147
A 65
32
d 100
o 111
u 117
b 98
l 108
e 101
32
q 113
u 117
o 111
t 116
e 101
” 148
ASP
� 8220
A 65
32
d 100
o 111
u 117
b 98
l 108
e 101
32
q 113
u 117
o 111
t 116
e 101
� 8221
As you can see, the double quotes are coming out as different characters in PHP and ASP, and the ASP ones aren't rendering correctly.
I'm running MySQL 5 on a windows machine using a standard Drupal install with PHP 5. ASP uses the MySQL ODBC 3.51 Driver and I'm not running any other commands in either PHP or ASP except to open a connection and run the select statement.
Edit As requested here is the asp script
Dim strConn, objConn, objRS, strQ
Dim i, strBody
strConn = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=" & strDBServer & "; DATABASE=studential; UID=" & strDBUser & ";PASSWORD=" & strDBPass & "; OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(strConn)
strQ = "select body from drupal_node_revisions where nid = 261"
Set objRS = objConn.Execute(strQ)
strBody = objRS("body")
For i = 1 To len(strBody)
Response.write(Mid(strBody, i, 1) & " " & AscW(Mid(strBody, i, 1)) & "<br />")
Next
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Further edit
When replacing the AscW with Asc in the line below:
Response.write(Mid(strBody, i, 1) & " " & AscW(Mid(strBody, i, 1)) & "<br />")
The character codes now match up, but the quote characters still display incorrctly. My page contains the utf-8 charset tag, so it may well be something before that is not using utf-8 encoding - any ideas what it may be or how I can fix it?
Thanks for your help,
Tom