0

tables in my database where are some unusual letters from czech alphabet like ěščřžýáíé ignore my query. I think it could be solve via CHARACTER SET utf8 COLLATE utf8_czech_ci, but it looks like i dont know how to use it. Iam trying this code, but for sure, there is some problem:

        mysql_query("CREATE TABLE `".$userreg."` CHARACTER SET utf8 COLLATE utf8_czech_ci(
        id INT NOT NULL AUTO_INCREMENT, 
        PRIMARY KEY(id),
        title VARCHAR(30), 
        rating_estimate INT)")
        or die(mysql_error());

I have to create table in PHP code, because it depends on another variables. Browser shows "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), title VARCHAR(30), ' at line 2".

Any idea how to fix?

Olda Stiller
  • 65
  • 1
  • 9
  • Since it appears you are creating a new MySQL database, I suggest using MySQLi or PDO for new code (and old code for that matter....) The mysqli_* library of functions has been deprecated. More information can be found in the PHP manual on ["Choosing an API"](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Crackertastic Dec 08 '14 at 21:41

2 Answers2

0
CHARACTER SET utf8 COLLATE utf8_czech_ci

needs to be at the end of the CREATE statement after the closing ')'

Hartmut Holzgraefe
  • 2,585
  • 12
  • 14
0

You can use mysql_set_charset()

mysql_set_charset('utf8');//or utf8_czech_ci

Or:

mysql_query("SET character_set_results=utf8"); 

You can also ALTER your table:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

However, it is suggested to see Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
Ali MasudianPour
  • 14,329
  • 3
  • 60
  • 62