public function save($dbConn = NULL)
    {
		$table = Backbone::getTable(get_called_class(), $dbConn);

		if (is_null($dbConn)) {
			$dbConn = Backbone::makeDbConn();
		}

        try {
            if (isset($this->record['dbData']) && is_array($this->record['dbData'])) {
                $sql = 'UPDATE ' . $table . ' SET ' . Backbone::tokenize(implode(',', Backbone::joinKeysAndValuesOfArray($this->record)), ',') . ' WHERE id=' . $this->record['dbData']['id'];
                $query = $dbConn->prepare($sql);
                $query->execute();
            } else {
                $sql = 'INSERT INTO ' . $table . ' (' . Backbone::tokenize(implode(',', array_keys($this->record)), ',') . ')' . ' VALUES ' . '(' . Backbone::tokenize(implode(',', Backbone::generateUnnamedPlaceholders($this->record)), ',') . ')';
                $query = $dbConn->prepare($sql);
                $query->execute(array_values($this->record));
            }
        } catch (PDOException $e) {
            return $e->getMessage();
        } finally {
            $dbConn = null;
        }

        return $query->rowCount();
    }
public function save($dbConn = NULL)
    {
		$table = Backbone::getTable(get_called_class(), $dbConn);

		if (is_null($dbConn)) {
			$dbConn = Backbone::makeDbConn();
		}

        try {
            if (isset($this->record['dbData']) && is_array($this->record['dbData'])) {
                $sql = 'UPDATE ' . $table . ' SET ' . Backbone::tokenize(implode(',', Backbone::joinKeysAndValuesOfArray($this->record)), ',') . ' WHERE id=' . $this->record['dbData']['id'];
                $query = $dbConn->prepare($sql);
                $query->execute();
            } else {
                $sql = 'INSERT INTO ' . $table . ' (' . Backbone::tokenize(implode(',', array_keys($this->record)), ',') . ')' . ' VALUES ' . '(' . Backbone::tokenize(implode(',', Backbone::generateUnnamedPlaceholders($this->record)), ',') . ')';
                $query = $dbConn->prepare($sql);
                $query->execute(array_values($this->record));
            }
        } catch (PDOException $e) {
            return $e->getMessage();
        } finally {
            $dbConn = null;
        }

        return $query->rowCount();
    }
public function save ( $ dbConn = NULL ) { $ table = Backbone :: getTable ( get_called_class ( ) , $ dbConn ) ; if ( is_null ( $ dbConn ) ) { $ dbConn = Backbone :: makeDbConn ( ) ; } try { if ( isset ( $ this -> record [ 'dbData' ] ) && is_array ( $ this -> record [ 'dbData' ] ) ) { $ sql = 'UPDATE ' . $ table . ' SET ' . Backbone :: tokenize ( implode ( ',' , Backbone :: joinKeysAndValuesOfArray ( $ this -> record ) ) , ',' ) . ' WHERE id=' . $ this -> record [ 'dbData' ] [ 'id' ] ; $ query = $ dbConn -> prepare ( $ sql ) ; $ query -> execute ( ) ; } else { $ sql = 'INSERT INTO ' . $ table . ' (' . Backbone :: tokenize ( implode ( ',' , array_keys ( $ this -> record ) ) , ',' ) . ')' . ' VALUES ' . '(' . Backbone :: tokenize ( implode ( ',' , Backbone :: generateUnnamedPlaceholders ( $ this -> record ) ) , ',' ) . ')' ; $ query = $ dbConn -> prepare ( $ sql ) ; $ query -> execute ( array_values ( $ this -> record ) ) ; } } catch ( PDOException $ e ) { return $ e -> getMessage ( ) ; } finally { $ dbConn = null ; } return $ query -> rowCount ( ) ; }
Insert or Update a record in a database table

@return bool|string
Insert or Update a record in a database table