PHP CREATE TABLE (mysql) encoding problem

Source: Internet
Author: User
Just contact PHP, according to the example written in the book, this is the code:
 
  

Run Error: An error occurred while building the table! Invalid default value for ' sex '.
My MySQL character set is: GBK. Online Search a lot, did not succeed, so the post solution. How to modify the code, have the idea of all give a hint, thank you first!


Reply to discussion (solution)

$con =mysql_connect ("localhost", "root", "MySQL");
mysql_query ("Set names GBK");
................

Try to run

$con =mysql_connect ("localhost", "root", "MySQL");
mysql_query ("Set names GBK");
................

Try it on the run, I can't.

$con =mysql_connect ("localhost", "root", "MySQL");
mysql_query ("Set names GBK");
................

Try it on, can you run it?

Save PHP file as GBK encoding and try again

$con =mysql_connect ("localhost", "root", "MySQL");
mysql_query ("Set names GBK");
................

In the run try I manually built a table, and then made a simple registration, can register successfully. And then back to use the original code to build a table, add mysql_query ("Set names GBK"), actually succeeded, hehe ... Really strange, Baidu, Google in the morning, this method also tried to not succeed in this post, hey. It's a success, freak! It should be your lucky, thanks! I'll give you the minute.

Save PHP file as GBK encoding and then try to mention this code ha, I also got the morning, did not make, because the Save as the encoding option is not GBK ah? How did you get that?

PHP file encoding to be consistent with the MySQL database encoding, as well as the MySQL database server encoding also must be consistent.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.