MySQL - What types of data should be enclosed in quotation marks?

5

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.

    
asked by anonymous 27.04.2017 / 20:26

1 answer

5

Numeric data does not need to be ;

Among the main ones:

NO ASPECTS : TINYINT , SMALLINT , MEDIUMINT , INT , INTEGER , BIGINT , FLOAT , DOUBLE , DOUBLE PRECISION , REAL and DECIMAL .

COM ASPECT (Date / time and string) : NUMERIC , DATE , DATETIME , TIMESTAMP , TIME , YEAR , CHAR , VARCHAR , TINYBLOB , TINYTEXT , BLOB , TEXT , MEDIUMBLOB , MEDIUMTEXT , LONGBLOB

Everyone has the MySQL Documentation .

    
27.04.2017 / 23:04