public function insert($table, $data = [])
    {
        // check if table name not empty
        if (!empty($table)) {
            // and array data not empty
            if (count($data) > 0 && is_array($data)) {
                // get array insert data in temp array
                $tmp = [];
                foreach ($data as $f => $v) {
                    $tmp[] = ":s_$f";
                }
                // make name space param for pdo insert statement
                $sNameSpaceParam = implode(',', $tmp);
                // unset temp var
                unset($tmp);
                // get insert fields name
                $sFields = implode(',', array_keys($data));
                // set pdo insert statement in class property
                $this->sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);";
                // pdo prepare statement
                $this->STH = $this->prepare($this->sql);
                // set class where property with array data
                $this->data = $data;
                // bind pdo param
                $this->_bindPdoNameSpace($data);
                // use try catch block to get pdo error
                try {
                    // execute pdo statement
                    if ($this->STH->execute()) {
                        // set class property with last insert id
                        $this->lastId = $this->lastInsertId();
                        // close pdo
                        $this->STH->closeCursor();
                        // return this object
                        return $this;
                    } else {
                        self::error($this->STH->errorInfo());
                    }
                } catch (\PDOException $e) {
                    // get pdo error and pass on error method
                    self::error($e->getMessage() . ': ' . __LINE__);
                }
            } else {
                self::error('Data not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }
public function insert($table, $data = [])
    {
        // check if table name not empty
        if (!empty($table)) {
            // and array data not empty
            if (count($data) > 0 && is_array($data)) {
                // get array insert data in temp array
                $tmp = [];
                foreach ($data as $f => $v) {
                    $tmp[] = ":s_$f";
                }
                // make name space param for pdo insert statement
                $sNameSpaceParam = implode(',', $tmp);
                // unset temp var
                unset($tmp);
                // get insert fields name
                $sFields = implode(',', array_keys($data));
                // set pdo insert statement in class property
                $this->sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);";
                // pdo prepare statement
                $this->STH = $this->prepare($this->sql);
                // set class where property with array data
                $this->data = $data;
                // bind pdo param
                $this->_bindPdoNameSpace($data);
                // use try catch block to get pdo error
                try {
                    // execute pdo statement
                    if ($this->STH->execute()) {
                        // set class property with last insert id
                        $this->lastId = $this->lastInsertId();
                        // close pdo
                        $this->STH->closeCursor();
                        // return this object
                        return $this;
                    } else {
                        self::error($this->STH->errorInfo());
                    }
                } catch (\PDOException $e) {
                    // get pdo error and pass on error method
                    self::error($e->getMessage() . ': ' . __LINE__);
                }
            } else {
                self::error('Data not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }
public function insert ( $ table , $ data = [ ] ) { // check if table name not empty if ( ! empty ( $ table ) ) { // and array data not empty if ( count ( $ data ) > 0 && is_array ( $ data ) ) { // get array insert data in temp array $ tmp = [ ] ; foreach ( $ data as $ f => $ v ) { $ tmp [ ] = ":s_$f" ; } // make name space param for pdo insert statement $ sNameSpaceParam = implode ( ',' , $ tmp ) ; // unset temp var unset ( $ tmp ) ; // get insert fields name $ sFields = implode ( ',' , array_keys ( $ data ) ) ; // set pdo insert statement in class property $ this -> sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);" ; // pdo prepare statement $ this -> STH = $ this -> prepare ( $ this -> sql ) ; // set class where property with array data $ this -> data = $ data ; // bind pdo param $ this -> _bindPdoNameSpace ( $ data ) ; // use try catch block to get pdo error try { // execute pdo statement if ( $ this -> STH -> execute ( ) ) { // set class property with last insert id $ this -> lastId = $ this -> lastInsertId ( ) ; // close pdo $ this -> STH -> closeCursor ( ) ; // return this object return $ this ; } else { self :: error ( $ this -> STH -> errorInfo ( ) ) ; } } catch ( \ PDOException $ e ) { // get pdo error and pass on error method self :: error ( $ e -> getMessage ( ) . ': ' . __LINE__ ) ; } } else { self :: error ( 'Data not in valid format..' ) ; } } else { self :: error ( 'Table name not found..' ) ; } }
Execute PDO Insert.

@param string $table
@param array  $data

@return self|void
Execute PDO Insert .