Failed to execute the table creation statement containing Chinese characters in php $ conn = mysql_connect ("localhost", "root ","");
If ($ conn ){
Mysql_select_db ("test", $ conn );
$ SQL = "create table user
(
Id int (5) not null auto_increment primary key,
Name char (10) not null default '',
Password char (12) not null default '',
Age int (3) not null default 0,
Sex char (10) not null default 'male ',
Mail char (50) not null default '',
Degree char (10) not null default''
);";
$ Do = mysql_query ($ SQL, $ conn );
If ($ do ){
Echo "operation successful ";
}
Else {
Echo "operation failed ";
}
} Else {
Echo "an error occurred while connecting to the server ";
}
Run the above code and return "operation failed ". I tested it myself and found it was a problem with Chinese characters, that is, the default sex field is 'male. However, if you run the statements in $ SQL separately in cmd, you can successfully create a table.
I don't know what is going on. I hope you can answer it.
Reply to discussion (solution)
Character set problems
After connecting to the database, run
Mysql_query ('set names ??? ');//??? Encode your program File (utf8 should be written for UTF-8)
Add default charset = gbk to the table creation statement