SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    issue in storing arabic characters..help please

    hello friend i have problem where the arabic fonts are not displaying in a proper manner in the database so please provide a solution for this...

    1)we used utf8 for the database.
    2)we tried utf_unicode_ci.
    3)we tried utf_general_ci.

    and i tried mysql_query(set names utf8);
    before the execution then too its not getting solved.
    in databse its showing ?????
    or some unwanted characters......

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    After some looking, I found: http://forums.mysql.com/read.php?103...144#msg-210144
    Try what was suggested there. I don't know Arabic, but have you tried to get data out -- like onto a webpage, how does it display?
    Ryan B | My Blog | Twitter

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,000
    Mentioned
    101 Post(s)
    Tagged
    0 Thread(s)
    What server-side langauge are you using? If it's php try adding this to the line imediatly after the database connection to MySQL is established:

    PHP Code:
    mysql_set_charset('utf8',$link_id); 
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are six things you need to do to ensure that Unicode is your default. Arabic can be stored and displayed if these are present:

    1) Each table must be set as utf8:
    CREATE TABLE name {
    ...
    } DEFAULT CHARACTER SET utf8;

    2) DB connection php code:
    PHP Code:
    <?php 
    $link 
    mysqli_connect('localhost''root''your password');
    ...
    if (!
    mysqli_set_charset($link'utf8'))
    {
    $output 'Cannot set utf8 encoding.';
    include 
    'your output.php'
    exit();
    }
    ?>
    This will connect you to the db with utf8, if not it will tell you so.

    3)
    echo out your values like this:
    PHP Code:
    <?php echo htmlspecialcharacters($table_name['value'], ENT_QUOTES'UTF-8'); ?>
    4)
    set your webpages as charset utf8 and save your code in utf8 encoding.

    5)Keep in mind that your command prompt window likely will not properly display the Arabic. It is better to echo the text onto a webpage which will display it properly.

    6) Finally, you should also make sure the browser you are using is properly configured to read utf8.

    That should cover it

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello friends for the replys for my issue but i applied ur command in the program then too i am not getting it solved

    i used a simple small program to solve this issue but its stores in the database???????? in this manner so i am pasting it below just friend go through it and make it correct and give me a reply as fas as u can


    <?php
    if(isset($_POST['submit']))
    {
    $conn = mysql_connect('localhost','root','local');
    mysql_select_db('test');
    //mysqli_set_charset('utf8',$conn);
    //mysql_set_charset('utf8',$conn);
    mysql_query("SET NAMES 'utf8'");
    mysql_query("SET CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'");




    /*if (!mysqli_set_charset($conn, 'utf8'))

    {
    echo htmlspecialcharacters($table_name['username2'], ENT_QUOTES, 'UTF-8');
    exit();
    }*/


    $sql="insert into testing(testfeild) values('".$_POST['hello']."')";
    //mysqli_query($conn,$sql);
    mysql_query($sql);
    echo $_POST['hello'];

    }
    ?>
    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <body>
    <form name="fname" method="post">
    helloinput type="text" name="hello" />
    <input type="submit" name="submit" value="submit" />
    </body>
    </html>

  6. #6
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kuttus011 View Post
    hello friends for the replys for my issue but i applied ur command in the program then too i am not getting it solved

    i used a simple small program to solve this issue but its stores in the database???????? in this manner so i am pasting it below just friend go through it and make it correct and give me a reply as fas as u can


    <?php
    if(isset($_POST['submit']))
    {
    $conn = mysql_connect('localhost','root','local');
    mysql_select_db('test');
    //mysqli_set_charset('utf8',$conn);
    //mysql_set_charset('utf8',$conn);
    mysql_query("SET NAMES 'utf8'");
    mysql_query("SET CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'");




    /*if (!mysqli_set_charset($conn, 'utf8'))

    {
    echo htmlspecialcharacters($table_name['username2'], ENT_QUOTES, 'UTF-8');
    exit();
    }*/


    $sql="insert into testing(testfeild) values('".$_POST['hello']."')";
    //mysqli_query($conn,$sql);
    mysql_query($sql);
    echo $_POST['hello'];

    }
    ?>
    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <body>
    <form name="fname" method="post">
    helloinput type="text" name="hello" />
    <input type="submit" name="submit" value="submit" />
    </body>
    </html>
    use proper code wrapping

  7. #7
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,000
    Mentioned
    101 Post(s)
    Tagged
    0 Thread(s)
    Change the line:

    PHP Code:
    //mysql_set_charset('utf8',$conn); 
    to

    PHP Code:
    mysql_set_charset('utf8',$conn); 
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    friend still in the database its showing in the manner of ????????? this just u run in ur system this and give me a solved solution friend ....

  9. #9
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kuttus011 View Post
    friend still in the database its showing in the manner of ????????? this just u run in ur system this and give me a solved solution friend ....
    First thing: How does it displays in the browser?
    And the other: Did you tried with following code after database connection?:
    PHP Code:
    mysql_query("SET NAMES 'utf8'");
    mysql_query("SET CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'"); 
    Lastly: How are you inserting the contents in DB: through form fields or manual insert in db?

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello friend i am inserting to the feilds through the form the program which i am used id above which u can see... and tell me the correction i need only one thing inside the database i should see it as in arabic when i enter it in arabic
    i tried it so many times friend just give me path way to lighten it up

  11. #11
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How does it display on your webpage? It will not display properly in your database window, so don't worry about it.

    Also your notes use mysqli but your code uses mysql. I would recommend upgrading to mysqli (mysql improved).

    You need to close with a </form> after you specify the input type.

    I recommend reading Kevin Yank's 'Build Your Own Database', especially chapters 2 - 4.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •