views:

29

answers:

1

I want to validate the data contained by Value Objects before inserting into the database (e.g. check that php string is smaller than 255 chars before inserting into a column of type varchar(255) or that a string is not inserted in an int(11) table column, php date has the correct format etc.).

Is there any framework or easy way to validate data before SQL INSERT or UPDATE operations?

Thanks!

+1  A: 

Is there any framework or easy way to validate data before SQL INSERT or UPDATE operations?

php has validation builtin the data filter package. I would not advice you to use a complicated framework for this, because it would kill your performance without any real benefits.

Alfred
This is the best solution by far. I had no idea there were validation functions built in PHP. Thanks a lot!
Cat
Hehe your welcome ;). If this is the best solution, you should accept it ;)(Maybe later after you have more answers??)
Alfred
Now an interesting question that came up is how to validate a nested POST array. So say I have an array that contains multiple arrays, do I use filter_input_array recursively or is there a more elegant solution?
Cat
Figured it out lol. You just do nested arrays and set 'flags' => FILTER_REQUIRE_ARRAY for each nested array :)
Cat
Nice :). Thanks for the approval :P
Alfred