Search code examples
phpmysqlcreate-table

How can Set character set utf8 and table rows collation in PHP mysql with query


I want to make table dynamically in PHP mysql and in table I want to set character set utf8 and its rows collation utf8_general_ci. I have no Clue

Anyone help please?

Here is my create table query:

CREATE TABLE `Table name` (
              `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
              `First name` TEXT( 9 ) NOT NULL,
              `Last name` TEXT NOT NULL,
              `email` TEXT NOT NULL,
              UNIQUE KEY id (id)
            );

How can I set "utf8" parameters in my query?


Solution

  • Try this nadeem

    CREATE TABLE `Table name` (
                  `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                  `First name` TEXT( 9 ) NOT NULL COLLATE 'utf8_general_ci',
                  `Last name` TEXT NOT NULL COLLATE 'utf8_general_ci',
                  `email` TEXT NOT NULL COLLATE 'utf8_general_ci',
                  UNIQUE KEY id (id)
                )COLLATE='utf8_general_ci';
    

    Do not collate on int, float data types