By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

Php retreiving data from mssql and special characters

P: n/a
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

Jul 11 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
eu*****@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.
js*******@attglobal.net
==================
Jul 11 '06 #2

P: n/a
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:
eu*****@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.
js*******@attglobal.net
==================
Jul 11 '06 #3

P: n/a
Mel
On 2006-07-11 23:25:45 +1000, eu*****@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:
>eu*****@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.
js*******@attglobal.net
=================
Grasping at straws, but have you checked the collation setting on the
MSSQL server?

Jul 11 '06 #4

P: n/a
eu*****@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.

Jul 11 '06 #5

P: n/a
Thank you all for the reply...

How do I flatten into an 8-bit encoding...?
Chung Leong wrote:
eu*****@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.
Jul 11 '06 #6

P: n/a
Discovered more information:

I changed my code from using
$dbh = DB::connect("mssql://sa:pa******@192.168.0.1/northwind"); to
simply using the freetds connection

putenv("FREETDSCONF=/etc/freetds.conf");
$db=mssql_connect("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:
eu*****@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.
Jul 11 '06 #7

P: n/a
deciacco wrote:
Discovered more information:

I changed my code from using
$dbh = DB::connect("mssql://sa:pa******@192.168.0.1/northwind"); to
simply using the freetds connection

putenv("FREETDSCONF=/etc/freetds.conf");
$db=mssql_connect("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

Jul 11 '06 #8

P: n/a
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("mssql://sa:password@MyServer2K/northwind");

Thank you!!

Chung Leong wrote:
deciacco wrote:
Discovered more information:

I changed my code from using
$dbh = DB::connect("mssql://sa:pa******@192.168.0.1/northwind"); to
simply using the freetds connection

putenv("FREETDSCONF=/etc/freetds.conf");
$db=mssql_connect("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
Jul 11 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.