Forum Moderators: coopster

Message Too Old, No Replies

PHP OOP function question

         

highseas

3:35 pm on Jun 6, 2011 (gmt 0)

10+ Year Member



This is a snippet from a class I am working with. Why does the delete() function call the save() function? Basically what should happen is new records are saved and old records are updated, and if a record needs to be deleted is should be marked as "deleted" by marking true or 1 in that mysql column.

Any insight is appreciated, or any opinions on this code (I co opted it and did not write it.... so feel free to be honest ;) )



public function save() {
if ($this->id == 0) {
$this->id = doInsert(self::db_table(), array(
array("name" => "id", "value" => 0)
));
}
doUpdate(self::db_table(), $this->id, array(
.
.
.
.


public function delete() {
if($this->id > 0) {
$this->deleted = true;
$this->save();
}
}

rocknbil

4:24 pm on Jun 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if a record needs to be deleted is should be marked as "deleted" by marking true or 1 in that mysql column.


You'd have to take a close look at the save function, which most likely does an update, but if the previous is true it's probably doing update table set deleted=1 where record=$id. This is pretty efficient I think, do all your updates in one place.

highseas

6:19 pm on Jun 6, 2011 (gmt 0)

10+ Year Member



hey rocknbil:

thanks for the reply. yes, all of the updates are done one "place," I was wondering if it would be quicker to use a separate function to just handle any deletes (by marking that record's field as 1 or true), just a quick function to tag that record as deleted separate from the "larger" save().

rocknbil

4:06 pm on Jun 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Quicker in what way, execution time? Probably not. If the "delete" is not a true delete and is just an update, it doesn't make a lot of sense to create the exact same task just to update the deleted field.