src/Base.php
public static function save()
    {
        try {
            $tableName = self::getTableName();
            $affectedRows = 0;
            $conn = self::getConnection();

            if(array_key_exists("id", self::$fields)){
                //update an existing record
                $sql = self::makeUpdateSQL();
            }
            else {
                //insert a new record
                $tableColumns = implode(", ", array_keys(self::$fields));
                $columnValues = "'".implode("', '", array_values(self::$fields))."'";
                $sql = "INSERT INTO ".$tableName."($tableColumns) VALUES($columnValues)";
            }

            $affectedRows = $conn->exec($sql);

            return $affectedRows;
        }
        catch(PDOException $pe) {
            return $pe->getMessage();
        }
        catch(Exception $e) {
            return $e->getMessage();
        }
    }
public static function save()
    {
        try {
            $tableName = self::getTableName();
            $affectedRows = 0;
            $conn = self::getConnection();

            if(array_key_exists("id", self::$fields)){
                //update an existing record
                $sql = self::makeUpdateSQL();
            }
            else {
                //insert a new record
                $tableColumns = implode(", ", array_keys(self::$fields));
                $columnValues = "'".implode("', '", array_values(self::$fields))."'";
                $sql = "INSERT INTO ".$tableName."($tableColumns) VALUES($columnValues)";
            }

            $affectedRows = $conn->exec($sql);

            return $affectedRows;
        }
        catch(PDOException $pe) {
            return $pe->getMessage();
        }
        catch(Exception $e) {
            return $e->getMessage();
        }
    }
public static function save ( ) { try { $ tableName = self :: getTableName ( ) ; $ affectedRows = 0 ; $ conn = self :: getConnection ( ) ; if ( array_key_exists ( "id" , self :: $ fields ) ) { //update an existing record $ sql = self :: makeUpdateSQL ( ) ; } else { //insert a new record $ tableColumns = implode ( ", " , array_keys ( self :: $ fields ) ) ; $ columnValues = "'" . implode ( "', '" , array_values ( self :: $ fields ) ) . "'" ; $ sql = "INSERT INTO " . $ tableName . "($tableColumns) VALUES($columnValues)" ; } $ affectedRows = $ conn -> exec ( $ sql ) ; return $ affectedRows ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
This method inserts a new record into the database table or updates an already existing record
This method inserts a new record into the database table or updates an already existing record