Hello everyone,

i spend many hours, by searching internet to answer my question, but didn't found a solution.

I'm using Debian 9, with apache2 and php 7.4 + ODBC Driver 17 for SQL Server, which by calling command:

odbc_connect("Driver={ODBC Driver 17 for SQL Server};Server=$host;Database=$dbname;", $user, $password);

is connecting to my Win 2019 SRV with MSSQL 2008 STD.

The problem appears, when in search variable are chars like ą, ę, ś, ć, (polish characters).
Without polish chars, everything works perfect, but with polish chars, i'm getting something like  szko�a instead szkoła in query, and empty response.


I notice that $search, which is coded in ASCI without polish chars and in UTF-8 with.

Database is collate polish_ci_as so it should understand utf8, but it doesnt.

I've tried some kind of decoding, encoding, etc. but nothing help.

Maybe someone had problem like this and could help me :)

I solved my problem by myself :)

The key to success was to change odbc by pdo_sqlsrv :)

$conn = new PDO(
            "sqlsrv:server=$serverName;Database=$database",
            $uid,
            $pwd,
            array(
               PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"

and now everything work brilliant :D

Thank You anyway ;)

Thank You for your answer.

My problem is to send properly format query from php to mssql (not mysql).

Mssql doesn't have problems with result query with polish chars. In my case, query:

SELECT name FROM object WHERE name like 'Szkoła'

In MSSQL profiler, looks like:

SELECT name FROM object WHERE name like 'Szko�a'

Which gives me 0 row result.

This is strange situation, because, if i avoid polish characters and send query, result is in UTF-8, with polish characters.

Of course, problem is with all polish characters, not only Ł :)
P.S.
I heard about using web service as some kind of proxy, to not connect php straight to Mssql, but i have not idea, how to do it :)

I solved my problem by myself :)

The key to success was to change odbc by pdo_sqlsrv :)

$conn = new PDO(
            "sqlsrv:server=$serverName;Database=$database",
            $uid,
            $pwd,
            array(
               PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"

and now everything work brilliant :D

Thank You anyway ;)

Read these next...

  • Curated What Spiceworld 2023 Meant to Me

    What Spiceworld 2023 Meant to Me

    Spiceworks

    So, it was my first year being a bonafide attendee, and I must say, the experience did not disappoint.   Three things come to mind:1) My co-workers - Much like all the IT Pros in how you all flock to Spiceworld each year to renew, rekindle and establish n...

  • Curated Server version migration advice

    Server version migration advice

    Windows

    In my current production setup, I have virtual (ESXI) 2 DC’s and 1 File Server running Windows Server 2012r2. As these are now EOL I am wanting to upgrade/migrate these 3 VM’s over to Window Server 2022. The ...

  • Curated Snap! -- Making Oxygen on Mars, The Dog Is Listening, Curing COPD, Goodbye Moon?

    Snap! -- Making Oxygen on Mars, The Dog Is Listening, Curing COPD, Goodbye Moon?

    Spiceworks Originals

    Your daily dose of tech news, in brief. Welcome to the Snap! Flashback: September 12, 1958: First Test of an Integrated Circuit (Read more HERE.) Bonus Flashback: September 12, 1992: Mae Jemison Becomes first African-American woman in spa...

  • Curated Brand Rep Wrap-Up: August 2023 🍏

    Brand Rep Wrap-Up: August 2023 🍏

    Partners

    Hi, y’all - Chad here. Well, I did it - I SURVIVED SPICEWORLD!! I hope you all did, too. While I was sweating off approximately half my body weight, I also managed to enjoy some good food, some great live music, and there’s a chance I may have made some n...

  • Curated Server Hard Drive setup

    Server Hard Drive setup

    Windows

    I have a new server with 4 hard drives.  Previously I would setup a RAID 5 and then a c: drive for the OS and then a second drive letter for the data.  I was wondering if this is still necessary or can I just put everything on the c: drive.  I don't have ...

  •