Postgres::insertRow PHP Метод

insertRow() публичный Метод

Adds a new row to a table
public insertRow ( $table, $fields, $values, $nulls, $format, $types ) : -1
$table The table in which to insert
$fields Array of given field in values
$values Array of new values for the row
$nulls An array mapping column => something if it is to be null
$format An array of the data type (VALUE or EXPRESSION)
$types An array of field types
Результат -1
    function insertRow($table, $fields, $values, $nulls, $format, $types)
    {
        if (!is_array($fields) || !is_array($values) || !is_array($nulls) || !is_array($format) || !is_array($types) || count($fields) != count($values)) {
            return -1;
        } else {
            // Build clause
            if (count($values) > 0) {
                // Escape all field names
                $fields = array_map(array('Postgres', 'fieldClean'), $fields);
                $f_schema = $this->_schema;
                $this->fieldClean($table);
                $this->fieldClean($f_schema);
                $sql = '';
                foreach ($values as $i => $value) {
                    // Handle NULL values
                    if (isset($nulls[$i])) {
                        $sql .= ',NULL';
                    } else {
                        $sql .= ',' . $this->formatValue($types[$i], $format[$i], $value);
                    }
                }
                $sql = "INSERT INTO \"{$f_schema}\".\"{$table}\" (\"" . implode('","', $fields) . "\")\n\t\t\t\t\tVALUES (" . substr($sql, 1) . ")";
                return $this->execute($sql);
            }
        }
        return -1;
    }
Postgres