set_$field($value)

A "setter" method will be automatically created for each variable of the class. The "setter" method is named the variable prepended by "set_" (e.g. set_person_id() set_name() set_email() set_age()).

The setter method takes a single variable as input and attempts to set the class variable to this inputted variable. Success returns true, failure returns false. The setter method checks to make sure the inputted variable meets the restrictions of the database (integer, double_precision, date, timestamp, character varying, etc.) If the "not null" flag is set in the database, an empty string will not be accepted. If the column is limited to a certain number of characters, this is also tested.

Additionally, you can add regular expression checking to a variable by putting the regular expression in the COMMENTS field in the database. To allow comments to be entered also, the regular expression pulled from the comments field must follow the double pipe "||". For example, the comments field of "email" could contain:

Person's email address. ||^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

which would add the following to the "setter" for email:

<?php
function set_email($val)
{
    ...

    if (!
preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"$email))
        return 
false;
    ...

?>


See also SQL Comment Options