Php retreiving data from mssql and special characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eugenio@iatmgu.com

    Php retreiving data from mssql and special characters

    Hi...not sure if this is the right group for this posting, but i'm
    don't know where else to post. I've got a simple problem...I have a
    linux box running apache 2.0 and php5. I'm trying to use the mssql
    functions in php to retreive data from a mssql server 2k. I'm pulling
    data from the customers table in the northwind db and i'm getting
    strange characters instead of special characters. Below is a sample
    output:

    (where the quotes are i get a question mark)
    What I'm getting:

    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquer?a - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbk?p - Christina Berglund


    What I should get:

    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquería - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbköp - Christina Berglund

  • Jerry Stuckle

    #2
    Re: Php retreiving data from mssql and special characters

    eugenio@iatmgu. com wrote:
    Hi...not sure if this is the right group for this posting, but i'm
    don't know where else to post. I've got a simple problem...I have a
    linux box running apache 2.0 and php5. I'm trying to use the mssql
    functions in php to retreive data from a mssql server 2k. I'm pulling
    data from the customers table in the northwind db and i'm getting
    strange characters instead of special characters. Below is a sample
    output:
    >
    (where the quotes are i get a question mark)
    What I'm getting:
    >
    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquer?a - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbk?p - Christina Berglund
    >
    >
    What I should get:
    >
    ALFKI - Alfreds Futterkiste - Maria Anders
    ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
    ANTON - Antonio Moreno Taquería - Antonio Moreno
    AROUT - Around the Horn - Thomas Hardy
    BERGS - Berglunds snabbköp - Christina Berglund
    >
    What charset are you using for your page? And what does the page source
    show?

    Probably alt.html might have been a better group to start, but this one
    is a logical choice.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • eugenio@iatmgu.com

      #3
      Re: Php retreiving data from mssql and special characters

      Thanks for the reply....

      I've tried utf-8 and ISO 8859-1 but I either get empty squares or
      question marks.
      The html source shows question marks as well. I'm guessing, but I think
      the problem may be that the mssql module is not able to handle the
      chars or something with the apache config. When I run the same script
      on win2k3 server with php and iis6 the characters show without a
      problem.

      Jerry Stuckle wrote:
      eugenio@iatmgu. com wrote:
      Hi...not sure if this is the right group for this posting, but i'm
      don't know where else to post. I've got a simple problem...I have a
      linux box running apache 2.0 and php5. I'm trying to use the mssql
      functions in php to retreive data from a mssql server 2k. I'm pulling
      data from the customers table in the northwind db and i'm getting
      strange characters instead of special characters. Below is a sample
      output:

      (where the quotes are i get a question mark)
      What I'm getting:

      ALFKI - Alfreds Futterkiste - Maria Anders
      ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
      ANTON - Antonio Moreno Taquer?a - Antonio Moreno
      AROUT - Around the Horn - Thomas Hardy
      BERGS - Berglunds snabbk?p - Christina Berglund


      What I should get:

      ALFKI - Alfreds Futterkiste - Maria Anders
      ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
      ANTON - Antonio Moreno Taquería - Antonio Moreno
      AROUT - Around the Horn - Thomas Hardy
      BERGS - Berglunds snabbköp - Christina Berglund
      >
      What charset are you using for your page? And what does the page source
      show?
      >
      Probably alt.html might have been a better group to start, but this one
      is a logical choice.
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Mel

        #4
        Re: Php retreiving data from mssql and special characters

        On 2006-07-11 23:25:45 +1000, eugenio@iatmgu. com said:
        Thanks for the reply....
        >
        I've tried utf-8 and ISO 8859-1 but I either get empty squares or
        question marks.
        The html source shows question marks as well. I'm guessing, but I think
        the problem may be that the mssql module is not able to handle the
        chars or something with the apache config. When I run the same script
        on win2k3 server with php and iis6 the characters show without a
        problem.
        >
        Jerry Stuckle wrote:
        >eugenio@iatmgu. com wrote:
        >>Hi...not sure if this is the right group for this posting, but i'm
        >>don't know where else to post. I've got a simple problem...I have a
        >>linux box running apache 2.0 and php5. I'm trying to use the mssql
        >>functions in php to retreive data from a mssql server 2k. I'm pulling
        >>data from the customers table in the northwind db and i'm getting
        >>strange characters instead of special characters. Below is a sample
        >>output:
        >>>
        >>(where the quotes are i get a question mark)
        >>What I'm getting:
        >>>
        >>ALFKI - Alfreds Futterkiste - Maria Anders
        >>ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
        >>ANTON - Antonio Moreno Taquer?a - Antonio Moreno
        >>AROUT - Around the Horn - Thomas Hardy
        >>BERGS - Berglunds snabbk?p - Christina Berglund
        >>>
        >>>
        >>What I should get:
        >>>
        >>ALFKI - Alfreds Futterkiste - Maria Anders
        >>ANATR - Ana Trujillo Emparedados y helados - Ana Trujillo
        >>ANTON - Antonio Moreno Taquería - Antonio Moreno
        >>AROUT - Around the Horn - Thomas Hardy
        >>BERGS - Berglunds snabbköp - Christina Berglund
        >>>
        >>
        >What charset are you using for your page? And what does the page source
        >show?
        >>
        >Probably alt.html might have been a better group to start, but this one
        >is a logical choice.
        >>
        >--
        >============== === Remove the "x" from my email address
        >Jerry Stuckle
        >JDS Computer Training Corp.
        >jstucklex@attgl obal.net
        >============== ===
        Grasping at straws, but have you checked the collation setting on the
        MSSQL server?

        Comment

        • Chung Leong

          #5
          Re: Php retreiving data from mssql and special characters

          eugenio@iatmgu. com wrote:
          Hi...not sure if this is the right group for this posting, but i'm
          don't know where else to post. I've got a simple problem...I have a
          linux box running apache 2.0 and php5. I'm trying to use the mssql
          functions in php to retreive data from a mssql server 2k. I'm pulling
          data from the customers table in the northwind db and i'm getting
          strange characters instead of special characters. Below is a sample
          output:
          The text columns in the Northwind database are all nvarchar/ntext--i.e.
          Unicode. These have to be flatten into an 8-bit encoding, since the
          libraries used by the mssql extension can't handle Unicode (nor can PHP
          itself for that matter).

          On Windows, I believe the encoding is determined by the current locale.
          On Linux, it's set in freetds.conf.

          Comment

          • deciacco

            #6
            Re: Php retreiving data from mssql and special characters

            Thank you all for the reply...

            How do I flatten into an 8-bit encoding...?


            Chung Leong wrote:
            eugenio@iatmgu. com wrote:
            Hi...not sure if this is the right group for this posting, but i'm
            don't know where else to post. I've got a simple problem...I have a
            linux box running apache 2.0 and php5. I'm trying to use the mssql
            functions in php to retreive data from a mssql server 2k. I'm pulling
            data from the customers table in the northwind db and i'm getting
            strange characters instead of special characters. Below is a sample
            output:
            >
            The text columns in the Northwind database are all nvarchar/ntext--i.e.
            Unicode. These have to be flatten into an 8-bit encoding, since the
            libraries used by the mssql extension can't handle Unicode (nor can PHP
            itself for that matter).
            >
            On Windows, I believe the encoding is determined by the current locale.
            On Linux, it's set in freetds.conf.

            Comment

            • deciacco

              #7
              Re: Php retreiving data from mssql and special characters

              Discovered more information:

              I changed my code from using
              $dbh = DB::connect("ms sql://sa:password@192 .168.0.1/northwind"); to
              simply using the freetds connection

              putenv("FREETDS CONF=/etc/freetds.conf");
              $db=mssql_conne ct("MyServer2k" ,"sa","password ");

              (freetds.conf setting)
              [MyServer2k]
              host = 192.168.0.1
              port = 1433
              tds version = 8.0

              when the script runs now I get this error:

              Warning: mssql_query() [function.mssql-query]: WARNING! Some
              character(s) could not be converted into client's character set.
              Unconverted bytes were changed to question marks ('?'). (severity 16)
              in /var/www/test/testing/index.php on line 31

              Same problem just wanted to add to it for other to see.


              deciacco wrote:
              Thank you all for the reply...
              >
              How do I flatten into an 8-bit encoding...?
              >
              >
              Chung Leong wrote:
              eugenio@iatmgu. com wrote:
              Hi...not sure if this is the right group for this posting, but i'm
              don't know where else to post. I've got a simple problem...I have a
              linux box running apache 2.0 and php5. I'm trying to use the mssql
              functions in php to retreive data from a mssql server 2k. I'm pulling
              data from the customers table in the northwind db and i'm getting
              strange characters instead of special characters. Below is a sample
              output:
              The text columns in the Northwind database are all nvarchar/ntext--i.e.
              Unicode. These have to be flatten into an 8-bit encoding, since the
              libraries used by the mssql extension can't handle Unicode (nor can PHP
              itself for that matter).

              On Windows, I believe the encoding is determined by the current locale.
              On Linux, it's set in freetds.conf.

              Comment

              • Chung Leong

                #8
                Re: Php retreiving data from mssql and special characters

                deciacco wrote:
                Discovered more information:
                >
                I changed my code from using
                $dbh = DB::connect("ms sql://sa:password@192 .168.0.1/northwind"); to
                simply using the freetds connection
                >
                putenv("FREETDS CONF=/etc/freetds.conf");
                $db=mssql_conne ct("MyServer2k" ,"sa","password ");
                >
                (freetds.conf setting)
                [MyServer2k]
                host = 192.168.0.1
                port = 1433
                tds version = 8.0
                >
                Try adding the line

                client charset = cp1250

                or
                client charset = utf8

                Comment

                • deciacco

                  #9
                  Re: Php retreiving data from mssql and special characters

                  That did it!!!

                  I don't quite understand how it works or why I needed to use the php
                  function putenv() but it works...

                  I added the line marked by -->

                  [MyServer2k]
                  host = 192.168.0.1
                  port = 1433
                  tds version = 8.0
                  -- client charset = UTF-8

                  and I went back to using PEAR:

                  $dbh = DB::connect("ms sql://sa:password@MyS erver2K/northwind");

                  Thank you!!

                  Chung Leong wrote:
                  deciacco wrote:
                  Discovered more information:

                  I changed my code from using
                  $dbh = DB::connect("ms sql://sa:password@192 .168.0.1/northwind"); to
                  simply using the freetds connection

                  putenv("FREETDS CONF=/etc/freetds.conf");
                  $db=mssql_conne ct("MyServer2k" ,"sa","password ");

                  (freetds.conf setting)
                  [MyServer2k]
                  host = 192.168.0.1
                  port = 1433
                  tds version = 8.0
                  >
                  Try adding the line
                  >
                  client charset = cp1250
                  >
                  or
                  client charset = utf8

                  Comment

                  Working...