Php and database problem in outputting russian language characters properly

Discussion in 'PHP' started by lokimona, Jul 5, 2008.

  1. #1
    Guys I'm using the code below to retrieve data from the database
    
    $lang_cat_table=mysql_query("select * from lang_cat_title where ID='$category_id'");
    PHP:
    It is working fine for English, but not for Russian language. How can I fix this up.?

    I found this trick on php.net ,.but..to be frank I don't know how to implement this on my page.

    Could you help me implement this code with my query and also to set charset to utf8.

    
    if (!function_exists('mysql_set_charset')) {
      function mysql_set_charset($charset,$dbh)
      {
        return mysql_query("set names $charset",$dbh);
      }
    }
    
    PHP:

    Please let me know if you are using any other way to output Russian characters on page,I appreciate you help.Thanks
     
    lokimona, Jul 5, 2008 IP
  2. chanakya

    chanakya Peon

    Messages:
    361
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You must have initiated a connection with db before executing the query

    Just apply the function on it
     
    chanakya, Jul 5, 2008 IP
  3. popol

    popol Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    this is the code you need:
    mysql_query("set names utf8");
    $lang_cat_table=mysql_query("select * from lang_cat_title where ID='$category_id'");
     
    popol, Jul 5, 2008 IP
  4. lokimona

    lokimona Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That helped popol but the characters are appearing strange ( not question marks ) on internet explorer .Its perfectly fine on firefox
     
    lokimona, Jul 5, 2008 IP
  5. popol

    popol Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well, that's not a server side(PHP) issue anymore.. it's a browser issue.. try searching in google for russian fonts, install it on you machine, then test again..
     
    popol, Jul 5, 2008 IP
  6. lokimona

    lokimona Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi popol, when i rechecked my page on firefox the russian characters are appearing strange as it was appearing on IE before, I think its not the fault with browser too. I can see the russian characters on other pages and I'm wondering why it isn't proper only on my pages.

    BTW I even checked using "set character set utf8" . Even it didn't work
     
    lokimona, Jul 5, 2008 IP
  7. lokimona

    lokimona Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I tried setting fonts and languages in firefox to support russian but nothing seems to be changed.
     
    lokimona, Jul 5, 2008 IP
  8. lokimona

    lokimona Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Its working fine now with

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    PHP:
    in header and
    mysql_query("set names 'utf8'"); before query.
    PHP:
    Thanks POPOL and forgive me for annoying you through PMing .
     
    lokimona, Jul 5, 2008 IP
  9. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #9
    You are right but only once once after connecting to database. It is not required before every query.
     
    mwasif, Jul 6, 2008 IP