skip to Main Content

This is my code:

  odbc_exec($conn,"SET client_encoding='UTF-8'");   
  $viewTablo= odbc_exec($conn,"SELECT A FROM B WHERE A='ÇŞÖ'");

Odbc execute doesn’t work with that ‘ÇŞÖ’ or any other Turkish character. How do I fix this?

Edit: I cannot change anything inside the database.

Code below is working.

 else if ($i==23 && odbc_result($viewTablo,$i)=="(Seçilmemiş)")
     {
    echo '
                          <td>
    <p class="text-xs text-center font-weight-bold mb-0"></p>
                         
                          </td>';              
   

Seems like it brings the result in utf-8 (or anything working) ,but anything I type on the .php file / input given inside the odbc_exec is not utf-8 (or whatever it needs) .

Besides, queries are working on the database itself.

I am open to any alternative to insert a ‘ÇŞÖ’ as parameter to database.

Thanks in advance.

4

Answers


  1. Can you try with the following added?

    odbc_exec($conn, "SET CLIENT_ENCODING='UTF-8'");
    odbc_exec($conn, "SET UNICODE_ENCODING=AL32UTF8");
    
    Login or Signup to reply.
  2. Have you checked that the database, database table, and the column are all UTF-8? This is crucial for it to work. These two queries does that:

    ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
    ALTER TABLE `tablename`
    MODIFY COLUMN `colname` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
    • Note that "text" in the second query should be the datatype you use in this column, as it could easily be varchar(255)

    Also, the file has to be UTF-8, and the old trick of using Notepad in windows to open the file and then go to File->Save as..->Choose UTF-8 in the "Ecoding" dropdown that should be on the left side of the "Save" button.

    Another thing that may be just an oversight, is that in your query you use A=’ÇŞÖ’ meaning it has to be exactly that, but it seems better here to use "A LIKE ‘%ÇŞÖ%’"

    Edit:

    For HANA, the SQL is similar:

    ALTER DATABASE <databasename> SET UNICODE ENCODING UTF8 COLLATION UNICODE_CI;
    
    ALTER TABLE <tablename> ALTER (<colname> NVARCHAR(100) COLLATE UNICODE_CI);
    

    Just make sure the NVARCHAR lenght is the same as your current.

    Login or Signup to reply.
  3. I have not used hana but based on some searches these are things are found that may work.

    try these strings as query and see if they work.

    $queryString = "SELECT A FROM B WHERE A='ÇŞÖ'";
    $queryString2 = utf8_encode($queryString);
    $queryString3 = utf8_decode($queryString);
    

    if you can change column type you can check this: insert a UTF-8 value into a SAP HANA database

    Also from back of my head you can check if your php file has BOM enabled. https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-with-bom#:~:text=There%20is%20no%20official%20difference,string%20from%20the%20file%2Fstream.

    Login or Signup to reply.
  4. Have you tried manually specifying a connection string (DSNless) using the necessary values from the specification for the database?

    PHP will accept a DSNless connection, directly entered into the first argument of the odbc_connect command, as per the documentation.

    From there, compare notes with the documentation for the connection for SAP HANA to build the connection string. You should be able to set your language and character set details directly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search