PHP/MySQL Hacks and Tutorials
- Details
- Category: PHP/MySQL Hacks and Tutorials
- Published on Saturday, Mar 26th 2011 9:33pm
Store money into MySQL
On many occasions developing E-Commerce applications, I've needed to recall the proper DB table column declarations for storing currency/money. I always forget, but I figured writing a blog post would make it easier for me to remember and for others to find on the web.
In order to store money/currency into MySQL, you will need to create a new table column and name it whatever you like...In this case we'll call it 'total_amount'. Set the data type (type) to FLOAT and the length/value properties to 10,2. This column's value will never be empty so we set Null to not null.
Let me take a moment and explain the FLOAT datatype. MySQL represents approximate numeric data values with the FLOAT or DOUBLE datatypes. Below is an explaination from MySQL's online documentation




















