Force variable types in php or mysql
Posted: Mon Mar 05, 2007 3:53 pm
In my framework I am starting to write in the ability to define a variable type and length for the variables that will be put into a query and then into a mysql database. My question is: is this even worth it or should I let mysql just do it all for me? I am already doing a variable type so that if its an id and they try to make it a string then it wont go into the db, it will just stay as 'null'.
Example, a sample Model class for my index looks like this:
and those variables 'value' can only be of that datatype. Also is that even worth it either or should I let mysql just do its own error checking and whatnot. I am also thinking about adding in the 'length' part there like I mentioned earlier.
I feel shady trusting security like that on a third party program (mysql) and hoping that it deals with everything properly. Am I just being too worrisome or is this a good step to forcing datatypes like other languages do?
Example, a sample Model class for my index looks like this:
Code: Select all
<?php
class indexModel extends modelBase
{
public $id = array(
'value' => null,
'type' => 'int',
);
public $name = array(
'value' => null,
'type' => 'string',
);
public $_table = 'nfw2_index';
}
?>I feel shady trusting security like that on a third party program (mysql) and hoping that it deals with everything properly. Am I just being too worrisome or is this a good step to forcing datatypes like other languages do?