src/EasyDB.php
public function insertGet(string $table, array $map, string $field)
    {
        if (empty($map)) {
            throw new \Exception('An empty array is not allowed for insertGet()');
        }
        if ($this->insert($table, $map) < 1) {
            throw new \Exception('Insert failed');
        }
        $post = [];
        $params = [];
        /**
         * @var string $i
         * @var string|bool|null|int|float $v
         */
        foreach ($map as $i => $v) {
            // Escape the identifier to prevent stupidity
            $i = $this->escapeIdentifier($i);
            if ($v === null) {
                $post []= " {$i} IS NULL ";
            } elseif (\is_bool($v)) {
                $post []= $this->makeBooleanArgument($i, $v);
            } else {
                // We use prepared statements for handling the users' data
                $post []= " {$i} = ? ";
                $params[] = $v;
            }
        }
        $conditions = \implode(' AND ', $post);
        // We want the latest value:
        switch ($this->dbEngine) {
            case 'mysql':
                $limiter = ' ORDER BY ' .
                $this->escapeIdentifier($field) .
                ' DESC LIMIT 0, 1 ';
                break;
            case 'pgsql':
                $limiter = ' ORDER BY ' .
                $this->escapeIdentifier($field) .
                ' DESC OFFSET 0 LIMIT 1 ';
                break;
            default:
                $limiter = '';
        }
        $query = 'SELECT ' .
                $this->escapeIdentifier($field) .
            ' FROM ' .
                $this->escapeIdentifier($table) .
            ' WHERE ' .
                $conditions .
                $limiter;
        return $this->single($query, $params);
    }
public function insertGet(string $table, array $map, string $field)
    {
        if (empty($map)) {
            throw new \Exception('An empty array is not allowed for insertGet()');
        }
        if ($this->insert($table, $map) < 1) {
            throw new \Exception('Insert failed');
        }
        $post = [];
        $params = [];
        /**
         * @var string $i
         * @var string|bool|null|int|float $v
         */
        foreach ($map as $i => $v) {
            // Escape the identifier to prevent stupidity
            $i = $this->escapeIdentifier($i);
            if ($v === null) {
                $post []= " {$i} IS NULL ";
            } elseif (\is_bool($v)) {
                $post []= $this->makeBooleanArgument($i, $v);
            } else {
                // We use prepared statements for handling the users' data
                $post []= " {$i} = ? ";
                $params[] = $v;
            }
        }
        $conditions = \implode(' AND ', $post);
        // We want the latest value:
        switch ($this->dbEngine) {
            case 'mysql':
                $limiter = ' ORDER BY ' .
                $this->escapeIdentifier($field) .
                ' DESC LIMIT 0, 1 ';
                break;
            case 'pgsql':
                $limiter = ' ORDER BY ' .
                $this->escapeIdentifier($field) .
                ' DESC OFFSET 0 LIMIT 1 ';
                break;
            default:
                $limiter = '';
        }
        $query = 'SELECT ' .
                $this->escapeIdentifier($field) .
            ' FROM ' .
                $this->escapeIdentifier($table) .
            ' WHERE ' .
                $conditions .
                $limiter;
        return $this->single($query, $params);
    }
public function insertGet ( string $ table , array $ map , string $ field ) { if ( empty ( $ map ) ) { throw new \ Exception ( 'An empty array is not allowed for insertGet()' ) ; } if ( $ this -> insert ( $ table , $ map ) < 1 ) { throw new \ Exception ( 'Insert failed' ) ; } $ post = [ ] ; $ params = [ ] ; /**
         * @var string $i
         * @var string|bool|null|int|float $v
         */ foreach ( $ map as $ i => $ v ) { // Escape the identifier to prevent stupidity $ i = $ this -> escapeIdentifier ( $ i ) ; if ( $ v === null ) { $ post [ ] = " {$i} IS NULL " ; } elseif ( \ is_bool ( $ v ) ) { $ post [ ] = $ this -> makeBooleanArgument ( $ i , $ v ) ; } else { // We use prepared statements for handling the users' data $ post [ ] = " {$i} = ? " ; $ params [ ] = $ v ; } } $ conditions = \ implode ( ' AND ' , $ post ) ; // We want the latest value: switch ( $ this -> dbEngine ) { case 'mysql' : $ limiter = ' ORDER BY ' . $ this -> escapeIdentifier ( $ field ) . ' DESC LIMIT 0, 1 ' ; break ; case 'pgsql' : $ limiter = ' ORDER BY ' . $ this -> escapeIdentifier ( $ field ) . ' DESC OFFSET 0 LIMIT 1 ' ; break ; default : $ limiter = '' ; } $ query = 'SELECT ' . $ this -> escapeIdentifier ( $ field ) . ' FROM ' . $ this -> escapeIdentifier ( $ table ) . ' WHERE ' . $ conditions . $ limiter ; return $ this -> single ( $ query , $ params ) ; }
Insert a new record then get a particular field from the new row

@param          string $table
@param          array  $map
@param          string $field
@return         mixed
@throws         \Exception
@psalm-suppress MixedAssignment
@psalm-suppress MixedArgument
Insert a new record then get a particular field from the new row