Results 1 to 6 of 6

Thread: Wrong characets in MS SQL output

  1. #1
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Wrong characets in MS SQL output

    I am a beginner, and learn as I make progress.
    I have successfully managed to retrieve data from my MS SQL server, but the output does not display the special characters right ( Swedish ).

    I have stated that the document should be utf-8 and the text above the database output comes out right, but not from the SQL Database.

    Output:

    Ansluten till Databasen.
    Nu är jag ansluten till databasen... Skickar en fråga till SQL-databasen...
    Antal funna rader: 10

    * 1234567 TEST TESTSSON Test S�GV�GEN 1 STOCKHOLM 019-20 53 39 TURE TESTSSON
    * 1900000 ANDREAS STIHL NORDEN AB GLIMMERV�GEN 6 STENKULLEN
    * 1900001 MALMBY MOTOR AB MALMBYV�GEN 2 STR�NGN�S 0152-250 72 JIMMY BJUR
    * 1900002 HEDMANS MOTOR AB NORRV�GEN 39 ARVIDSJAUR 0960-123 41 TOMMY HEDMAN
    * 1900003 G�TEBORGS SKOG & TR�DG�RD AB DATAV�GEN 21 A ASKIM 031-68 38 80 BJ�RN HASSLING
    * 1900004 TINGSRYDS MOTORTJ�NST L�V�NGEN PL 1068 TINGSRYD 0477-105 46 INGE SVENSSON
    * 1900005 HILDINGS MOTOR INDUSTRIV�GEN 4 YTTERHOGDAL 0680-600 77 HILDING
    * 1900006 KUNGSBACKA J�RN & FRITID AB TEKNIKGATAN 8 KUNGSBACKA 0300-188 00 MIKAEL DELLN�S
    * 1900007 PSB MASKIN AB NORRBACKAGATAN 23 STOCKHOLM 08-33 78 80 PUTTE N�TBERG
    * 1900008 S�G & TR�DG�RDSCENTER BOX 111 S�FFLE 0533-101 90 PER-�KE VARILENGEN

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<title>PHP test</title>
    	<meta http-equiv="content-type"
    		content="text/html; charset=utf-8/>
    </head>
    <?php
      $db = mssql_connect('SERVERNAME', 'USER','PASSWORD');
      if (!$db)
     
    {
        $output= 'Uppkopplingen gick inte bra.';
       echo $output;
       exit();
    }
    else
    {
        mssql_select_db('[DATABASE]',$db);
        $output= 'Ansluten till Databasen.<br>';
           echo $output;
       
    } 
    echo 'Nu är jag ansluten till databasen... Skickar en fråga till SQL-databasen...<br>';
    // Send a select query to MSSQL
    $query = mssql_query('select top 10 No_, Name, Address, City, [Contact person], [Phone No_] from [STIHL SE$Customer]where Market=1');
    
    
    // Check if there were any records
    if (!mssql_num_rows($query)) {
        echo 'Hittade inga poster';
    } else 
    {
    	echo 'Antal funna rader: ' . mssql_num_rows($query) . '<br>';
        // The following is equal to the code below:
        //
        // while ($row = mssql_fetch_row($query)) 
    
    
    echo '<ul>';
    
        while ($row = mssql_fetch_assoc($query)) {
            echo '<li>' . $row['No_'] . ' '. $row['Name'] .' '. $row['Address'].' '. $row['City'] .' '. $row['Phone No_'] .' '. $row['Contact person'] .'</li>';
        }
    
    echo '</ul>';
        
    }
    // Free the query result
    mssql_free_result($query);
    ?>
    Any suggestions?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Everything must be UTF8-- the database, your html pages, possibly your server configuration, etc. Go through and make sure everything is set to UTF8 and you should find the problem.

    UTF8 is a setting for how a certain program will read information. If even one part is set to something else, then it will be translated into a weird format.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK I understand, but still not...

    Surely there must be some way of handling different character sets? I am not allowed to change the collation of the database which is set to 'SQL_Latin1_General_CP850_CS_AS'... And what character set in HTML/PHP corresponds to that ?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's probably ISO. You can serve your page as ISO, and because Swedish is not that weird (compared to characters like in Chinese or Russian), I think ISO will be ok. Then you will need to use the same format in your html, etc.
    Also, there are functions in PHP that could convert it if you want to use unicode, such as utf8_encode().
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Interesting... I've got a bunch of new stuff to try out. Thanks man!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sorry I don't have more specific advice, and I hope that works. It's always difficult to coordinate all the formats, but after you work this out it will always be correct (unless you change servers or something). So at least that's nice.

    By the way, two ideas to help:
    1. Do you have phpmyadmin or another web interface? I don't know what ms sql uses, but that's common for mysql. If you do, then you could look at what encoding those pages are being sent in and see if that helps at all.
    2. If you google specific terms (encodings, database configurations, etc.) all in quotes (separately), then you might find someone else who had this same problem and solved it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •