Having a generic data type for a database table column, is it "good" practice?
- by Yanick Rochon
I'm working on a PHP project where some object (class member) may contain different data type. For example :
class Property {
private $_id; // (PK)
private $_ref_id; // the object reference id (FK)
private $_name; // the name of the property
private $_type; // 'string', 'int', 'float(n,m)', 'datetime', etc.
private $_data; // ...
// ..snip.. public getters/setters
}
Now, I need to perform some persistence on these objects. Some properties may be a text data type, but nothing bigger than what a varchar may hold. Also, later on, I need to be able to perform searches and sorting.
Is it a good practice to use a single database table for this (ie. is there a non negligible performance impact)? If it's "acceptable", then what could be the data type for the data column?