public function insert($table, $data)
    {
        $fieldNames = implode(',', array_keys($data));
        $fieldValues = ':'.implode(', :', array_keys($data));

        $query = "INSERT INTO $table ($fieldNames) VALUES($fieldValues)";
        $this->prepare($query);

        /**
         * Iterate through data then bind the values
         */
        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }

        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }
public function insert($table, $data)
    {
        $fieldNames = implode(',', array_keys($data));
        $fieldValues = ':'.implode(', :', array_keys($data));

        $query = "INSERT INTO $table ($fieldNames) VALUES($fieldValues)";
        $this->prepare($query);

        /**
         * Iterate through data then bind the values
         */
        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }

        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }
public function insert ( $ table , $ data ) { $ fieldNames = implode ( ',' , array_keys ( $ data ) ) ; $ fieldValues = ':' . implode ( ', :' , array_keys ( $ data ) ) ; $ query = "INSERT INTO $table ($fieldNames) VALUES($fieldValues)" ; $ this -> prepare ( $ query ) ; /**
         * Iterate through data then bind the values
         */ foreach ( $ data as $ key => $ value ) { $ this -> bind ( ":$key" , $ value ) ; } try { $ this -> execute ( ) ; return true ; } catch ( PDOException $ e ) { echo $ e -> errorInfo [ 2 ] ; return false ; } }
Insert data into the table
@param  string $table table in which you want to insert values
@param  array $data  an array containing names of fields and the
data ypu want to enter
@return BOOL true or false depending on the success
Insert data into the table