I want to save the timestamp in which the row was inserted into the MySQL table with the row, in order to later compare it with others. What is the best type of field for this and what is the best way to insert a timestamp string in PHP?
Use TIMESTAMP DEFAULT CURRENT_TIMESTAMP . This will create a TIMESTAMP field that will be set to INSERT, but not to UPDATE.
TIMESTAMP DEFAULT CURRENT_TIMESTAMP
Use TIMESTAMP as the field type. All TIMESTAMP field types will have CURRENT_TIMESTAMP as the default value (which is an alias for NOW ())
When adding an entry, write '' in this field - this will take the default time as the value.
''
Use TIMESTAMP NOT NULL
TIMESTAMP NOT NULL
When you execute INSERT and leave this column, the default will be CURRENT_TIMESTAMP
INSERT
CURRENT_TIMESTAMP
Use the DateTime data type for the NOW () column to set the current time and the UNIX_TIMESTAMP () function if you need to compare it using PHP