RedBeanPHP\QueryWriter\AQueryWriter::insertRecord PHP Method

insertRecord() protected method

Inserts a record into the database using a series of insert columns and corresponding insertvalues. Returns the insert id.
protected insertRecord ( $type, array $insertcolumns, array $insertvalues ) : integer
$insertcolumns array columns to be inserted
$insertvalues array values to be inserted
return integer
    protected function insertRecord($type, $insertcolumns, $insertvalues)
    {
        $default = $this->defaultValue;
        $suffix = $this->getInsertSuffix($type);
        $table = $this->esc($type);
        if (count($insertvalues) > 0 && is_array($insertvalues[0]) && count($insertvalues[0]) > 0) {
            $insertSlots = array();
            foreach ($insertcolumns as $k => $v) {
                $insertcolumns[$k] = $this->esc($v);
                if (isset(self::$sqlFilters['w'][$type][$v])) {
                    $insertSlots[] = self::$sqlFilters['w'][$type][$v];
                } else {
                    $insertSlots[] = '?';
                }
            }
            $insertSQL = "INSERT INTO {$table} ( id, " . implode(',', $insertcolumns) . " ) VALUES\n\t\t\t( {$default}, " . implode(',', $insertSlots) . " ) {$suffix}";
            $ids = array();
            foreach ($insertvalues as $i => $insertvalue) {
                $ids[] = $this->adapter->getCell($insertSQL, $insertvalue, $i);
            }
            $result = count($ids) === 1 ? array_pop($ids) : $ids;
        } else {
            $result = $this->adapter->getCell("INSERT INTO {$table} (id) VALUES({$default}) {$suffix}");
        }
        if ($suffix) {
            return $result;
        }
        $last_id = $this->adapter->getInsertID();
        return $last_id;
    }