[ create a new paste ] login | about

Link: http://codepad.org/Vj97OcC0    [ raw code | output | fork ]

PHP, pasted on Jul 31:
function add_person($conn, $tax_code, $name, $surname, $born_on, $born_at, $residence_at, $sex, $cell_number = null, $home_numer = null, $office_numer = null) {
    $stmt = $conn->prepare
        ("CALL add_person
              ( :tax_code
              , :name
              , :surname
              , :born_on
              , :born_at
              , :residence_at
              , :sex
              , :cell_number
              , :home_number
              , :office_number )");
    if (!\api\validation\is_tax_code($tax_code))
        throw new \api\exceptions\error('invalid_tax_code');
    else $stmt->bindValue('tax_code', $tax_code);
    if (!\api\validation\is_name($name))
        throw new \api\exceptions\error('invalid_name');
    else $stmt->bindValue('name', $name);
    if (!\api\validation\is_surname($surname))
        throw new \api\exceptions\error('invalid_surname');
    else $stmt->bindValue('surname', $surname);
    if (!\api\validation\is_date($born_on))
        throw new \api\exceptions\error('invalid_born_on_date');
    else $stmt->bindValue('born_on', $born_on);
    if (!\api\validation\is_location($born_at))
        throw new \api\exceptions\error('invalid_born_at_location');
    else $stmt->bindValue('born_at', $born_at);
    if (!\api\validation\is_location($residence_at))
        throw new \api\exceptions\error('invalid_residence_at_location');
    else $stmt->bindValue('residence_at', $residence_at);
    if (!\api\validation\is_sex($sex))
        throw new \api\exceptions\error('invalid_sex');
    else $stmt->bindValue('sex', $sex);

    if (!empty($cell_number))
        if (!\api\validation\is_number($cell_number))
            throw new \api\exceptions\error('invalid_cell_number');
        else $stmt->bindValue('cell_number', $cell_number);
    else $stmt->bindValue('cell_number', null, \PDO::PARAM_NULL);
    if (!empty($cell_number))
        if (!\api\validation\is_number($home_number))
            throw new \api\exceptions\error('invalid_home_number');
        else $stmt->bindValue('home_number', $home_number);
    else $stmt->bindValue('home_number', null, \PDO::PARAM_NULL);
    if (!empty($cell_number))
        if (!\api\validation\is_number($office_number))
            throw new \api\exceptions\error('invalid_office_number');
        else $stmt->bindValue('office_number', $office_number);
    else $stmt->bindValue('office_number', null, \PDO::PARAM_NULL);
}


Output:
function add_person($conn, $tax_code, $name, $surname, $born_on, $born_at, $residence_at, $sex, $cell_number = null, $home_numer = null, $office_numer = null) {
    $stmt = $conn->prepare
        ("CALL add_person
              ( :tax_code
              , :name
              , :surname
              , :born_on
              , :born_at
              , :residence_at
              , :sex
              , :cell_number
              , :home_number
              , :office_number )");
    if (!\api\validation\is_tax_code($tax_code))
        throw new \api\exceptions\error('invalid_tax_code');
    else $stmt->bindValue('tax_code', $tax_code);
    if (!\api\validation\is_name($name))
        throw new \api\exceptions\error('invalid_name');
    else $stmt->bindValue('name', $name);
    if (!\api\validation\is_surname($surname))
        throw new \api\exceptions\error('invalid_surname');
    else $stmt->bindValue('surname', $surname);
    if (!\api\validation\is_date($born_on))
        throw new \api\exceptions\error('invalid_born_on_date');
    else $stmt->bindValue('born_on', $born_on);
    if (!\api\validation\is_location($born_at))
        throw new \api\exceptions\error('invalid_born_at_location');
    else $stmt->bindValue('born_at', $born_at);
    if (!\api\validation\is_location($residence_at))
        throw new \api\exceptions\error('invalid_residence_at_location');
    else $stmt->bindValue('residence_at', $residence_at);
    if (!\api\validation\is_sex($sex))
        throw new \api\exceptions\error('invalid_sex');
    else $stmt->bindValue('sex', $sex);

    if (!empty($cell_number))
        if (!\api\validation\is_number($cell_number))
            throw new \api\exceptions\error('invalid_cell_number');
        else $stmt->bindValue('cell_number', $cell_number);
    else $stmt->bindValue('cell_number', null, \PDO::PARAM_NULL);
    if (!empty($cell_number))
        if (!\api\validation\is_number($home_number))
            throw new \api\exceptions\error('invalid_home_number');
        else $stmt->bindValue('home_number', $home_number);
    else $stmt->bindValue('home_number', null, \PDO::PARAM_NULL);
    if (!empty($cell_number))
        if (!\api\validation\is_number($office_number))
            throw new \api\exceptions\error('invalid_office_number');
        else $stmt->bindValue('office_number', $office_number);
    else $stmt->bindValue('office_number', null, \PDO::PARAM_NULL);
}


Create a new paste based on this one


Comments: