How PHP inserts an empty string into mysql datetime or int

Source: Internet
Author: User
Keywords Php mysql
MySQL table structure where the fields my_dateDateTime DEFAULT NULL,
See a simple Insert code first
$sql = "INSERT into My_test (my_date) VALUES (')";
Mysqli_query ($DBC, $sql);

Insert failed How do I insert an empty string into mysql datetime or int?

Of course I also know $sql = "INSERT into My_test (my_date) VALUES (null)"; can be inserted successfully;
But the insert code is that my backup database (. sql) automatically generates an empty string instead of NULL if the datetime itself does not have data, then it cannot be inserted properly? Or how to output insert into My_test (my_date) VALUES (NULL) this null in. sql?
Experts online, such as!!!!!!!!!!!!!!

Reply content:

MySQL table structure where the fields are my_date datetime DEFAULT NULL,
See a simple Insert code first
$sql = "INSERT into My_test (my_date) VALUES (')";
Mysqli_query ($DBC, $sql);

Insert failed How do I insert an empty string into mysql datetime or int?

Of course I also know $sql = "INSERT into My_test (my_date) VALUES (null)"; can be inserted successfully;
But the insert code is that my backup database (. sql) automatically generates an empty string instead of NULL if the datetime itself does not have data, then it cannot be inserted properly? Or how to output insert into My_test (my_date) VALUES (NULL) this null in. sql?
Experts online, such as!!!!!!!!!!!!!!

Sets the default string to null or directly executes SQL a value that is set to empty

String can only be inserted in a type field such as varchar char text
int datatime can be null, but only if the field is designed to allow null

How do you lead the curiosity, NULL export SQL statement is empty string?

Can't answer you, must not be.
You have a problem when you back up, NULL is NULL, can not become ", or use the normal way to import export data, such as the mysqldump command, or through phpMyAdmin, Navicat for MySQL and other tools.

  • Related Article

    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.