public function save()
    {
        $result;
        if (! self::$id) {
            // new record so we insert
            $query = "INSERT INTO $this->tableName (".implode(", ", array_keys($this->props)).") VALUES(";

            for ($i = 0; $i < count($this->props); $i++) {
                $query .= "?";

                if ($i != count($this->props) - 1) {
                    $query .= ",";
                }
            }

            $query .= ");";

            $insert = Connection::db()->prepare($query);
            $result = $insert->execute(array_values($this->props));
        } else {
            // existing record, se we update
            $query = "UPDATE $this->tableName SET ";

            $count = 0;
            foreach ($this->props as $key => $value) {
                $query .= "$key = '$value'";

                if ($count != count($this->props) - 1) {
                    $query .= ",";
                }
                $count++;
            }

            $query .= " WHERE id = ".self::$id;
            $result = Connection::db()->query($query);
        }

        if (! $result) {
            return false;
        } else {
            return true;
        }
    }
public function save()
    {
        $result;
        if (! self::$id) {
            // new record so we insert
            $query = "INSERT INTO $this->tableName (".implode(", ", array_keys($this->props)).") VALUES(";

            for ($i = 0; $i < count($this->props); $i++) {
                $query .= "?";

                if ($i != count($this->props) - 1) {
                    $query .= ",";
                }
            }

            $query .= ");";

            $insert = Connection::db()->prepare($query);
            $result = $insert->execute(array_values($this->props));
        } else {
            // existing record, se we update
            $query = "UPDATE $this->tableName SET ";

            $count = 0;
            foreach ($this->props as $key => $value) {
                $query .= "$key = '$value'";

                if ($count != count($this->props) - 1) {
                    $query .= ",";
                }
                $count++;
            }

            $query .= " WHERE id = ".self::$id;
            $result = Connection::db()->query($query);
        }

        if (! $result) {
            return false;
        } else {
            return true;
        }
    }
public function save ( ) { $ result ; if ( ! self :: $ id ) { // new record so we insert $ query = "INSERT INTO $this->tableName (" . implode ( ", " , array_keys ( $ this -> props ) ) . ") VALUES(" ; for ( $ i = 0 ; $ i < count ( $ this -> props ) ; $ i ++ ) { $ query .= "?" ; if ( $ i != count ( $ this -> props ) - 1 ) { $ query .= "," ; } } $ query .= ");" ; $ insert = Connection :: db ( ) -> prepare ( $ query ) ; $ result = $ insert -> execute ( array_values ( $ this -> props ) ) ; } else { // existing record, se we update $ query = "UPDATE $this->tableName SET " ; $ count = 0 ; foreach ( $ this -> props as $ key => $ value ) { $ query .= "$key = '$value'" ; if ( $ count != count ( $ this -> props ) - 1 ) { $ query .= "," ; } $ count ++ ; } $ query .= " WHERE id = " . self :: $ id ; $ result = Connection :: db ( ) -> query ( $ query ) ; } if ( ! $ result ) { return false ; } else { return true ; } }
Save either a new or existing record
@return integer 1 is successful, 0 if false
Save either a new or existing record