6

i have a database in MsSQL, with which i connect from my PHP code through PDO objects. the database has column "Kadź".

Now - if i execute a

SELECT Kadź FROM <tablename>

query from my SQL Server Management Studio - everything works fine, i get the results. However, when i try to execute a

$sql = "SELECT Kadź FROM <tablename>";

i recieve a

SQLSTATE[HY000]: General error: 207 General SQL Server error: Check messages from the SQL Server [207] (severity 16) [(null)]

error. Querying any other column doesn't produce any problems, but this one does. I suspect it's because of that "ź" character in the name of this column, that is unproperly encoded on the route between my PHP code and the database.

The collation used by my server is "Polish_Cl_Al". i've tried fixing it by adding attribute

$this->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAME'utf8'");

but the PDO answered me, that the driver doesn't support it...

thanks in advance for any help

2
  • What is the encoding of your PHP file: Polish or UTF-8? Commented Aug 22, 2012 at 7:19
  • the encoding of my php is utf-8 Commented Aug 22, 2012 at 7:28

1 Answer 1

5

You can try:

$pdo = new PDO('dblib:host=localhost;dbname=databasename;charset=UTF-8', 'username', 'password');

or (for windows)

$smth->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);
Sign up to request clarification or add additional context in comments.

9 Comments

yeah, i've tried that too, i get PHP Warning: PDO::__construct(): SQLSTATE[IM001]: Driver does not support this function: driver does not support setting attributes in ...
thank you. however still - General error: 195 General SQL Server error: Check messages from the SQL Server [195] (severity 15) [SET NAMES 'utf8']
unfortunately it doesn't change anything either. General Error 207 appeared again.
I'm sorry, I must be blind, I saw MySQL first time. Try that command, it's UTF-8 for MsSQL
And within setAttribute .. ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.