I am very new to php and mysql so sorry if this is a silly question,
I am importing some measurement data into the database via PhP My Admin.
The CSV has values going from 1 to 3000, some have decimals and some don't.
Due to this I don't think the table likes the mix up.
Most of the values show correctly, apart from when the values go over 999, one of the measurement values shows 999.99 for a value of 1138.
Is there any way to stop it doing this?
Thanks for any advice!
Well, that's the problem, data type. As per the docs:
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The
ranges of values for the arguments in MySQL 5.6 are as follows:
M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL permitted a range of 1 to 254.)
D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.
So your DECIMAL(5,2)
column type can hold numbers up to 999.99
. You'll have to alter the table and make the column larger.
(As about why MySQL prefers to corrupt your data rather than reporting it, well, that's been its philosophy from the early years. You can play with SQL modes to fix that.)