Find the answer to your Linux question:
Results 1 to 3 of 3
1) if i dont wont to have a problems with Unicode (when i conntect information from database in PHP) Where should I write "CHARACTER SET utf8 COLLATE utf8_general_ci?". whre should ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    8

    SQL problems with UNIXODE


    1) if i dont wont to have a problems with Unicode (when i conntect information from database in PHP) Where should I write "CHARACTER SET utf8 COLLATE utf8_general_ci?".

    whre should i Write this code when I Creat DATABASE OR TABLE?

    2) should i write down this 2 code In php file?
    Code:
    mysql_query("SET CHARACTER SET utf8");
    mysql_query ("SET NAMES 'utf8'") ;
    3) what is diference between this codes? which is good and bed and why?

    For example My SQL code is like this:
    is my code Correct?
    Code:
    CREATE DATABASE `VakhoQ` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    
    CREATE TABLE `VakhoQ`.`C_lessons` (
    
    `id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    
    `title` VARCHAR( 225 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
    
    `description` VARCHAR( 225 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
    
    `text` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL 
    
    ) ENGINE = MYISAM 
    
    
    
    ////////////////////////////

    I have Creted Database named "vakhoQ"

    then I make table c_lessons with "id", "title", "Description", and "text"

  2. #2
    Linux User Manko10's Avatar
    Join Date
    Sep 2010
    Posts
    250
    SET NAMES utf8 is a shortcut for
    Code:
    SET character_set_client = utf8;
    SET character_set_results = utf8;
    SET character_set_connection = utf8;
    whereas SET CHARACTER SET utf8 is a shortcut for
    Code:
    SET character_set_client = utf8;
    SET character_set_results = utf8;
    SET collation_connection = @@collation_database;
    You see, they are basically the same, but SET CHARACTER SET also sets collation_connection (which again sets character_set_connection implicitly). For more information about what these directives mean, please read the manual.
    SET CHARACTER SET can cause some problems when handling data of different character set, so normally you would just use SET NAMES. You should not use both. In either case, the directive has to be the very first query sent after opening the connection.
    Refining Linux Advent calendar: 24 Outstanding ZSH Gems

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Posts
    8
    thanks a lot!

    now, i know that i should use "SET NAMES utf8" In php file.

    but will i write in SQL lite "CHARACTER SET utf8 COLLATE utf8_general_ci" when I creat Database and Table?

    Dose the the both (tabe and database) need " CHARACTER SET utf8 COLLATE utf8_general_ci" ?

Posting Permissions

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