I'm developing a script for backup / dump from my database via PHP , but when saving the file, I need to put quotation marks according to type of the column.
So far so good! But what data types should be enclosed in quotation marks?Example:
-
Integer :
123
-INT()
-
String :
'123'
-VARCHAR()
I need a complete list of data types and whether or not they should be enclosed in quotation marks, and I have not found a satisfactory list in my searches.
A more detailed example of where I want to go:
mysql> explain teste;
+-----------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------------------+----------------+
| controle | int(10) | NO | PRI | NULL | auto_increment |
| inteiro | int(1) | NO | | 0 | |
| flutuante | float | NO | | 0.1 | |
| string | varchar(150) | NO | | fubá | |
| datahora | datetime | NO | | 0000-00-00 00:00:00 | |
+-----------+--------------+------+-----+---------------------+----------------+
In the final file ( dump ), the lines to insert the data of this table looks like this:
INSERT INTO 'teste' VALUES (1,0,0.1,'fubá','0000-00-00 00:00:00');
Note that the INT
and FLOAT
types are not enclosed in quotation marks. The VARCHAR
and DATETIME
types are enclosed in quotation marks.