Skip to content

Commit

Permalink
Merge pull request trongate#152 from monxian/modelUpdate
Browse files Browse the repository at this point in the history
Improvement on update function in Model
  • Loading branch information
trongate authored Sep 6, 2023
2 parents d91eaf0 + a7ccabd commit 990a50c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions engine/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public function insert($data, $target_tbl = null) {
return $id;
}


public function update($update_id, $data, $target_tbl = null) {

if (!isset($target_tbl)) {
Expand All @@ -427,6 +428,33 @@ public function update($update_id, $data, $target_tbl = null) {
$this->prepare_and_execute($sql, $data);
}

public function update_where($column, $column_value, $data, $target_tbl = null) {

if (!isset($target_tbl)) {
$target_tbl = $this->get_table_from_url();
}

$sql = "UPDATE `$target_tbl` SET ";

foreach ($data as $key => $value) {
$sql .= "`$key` = :$key, ";
}

$sql = rtrim($sql, ', ');
$sql .= " WHERE `$target_tbl`.`$column` = :value";

$data['value'] = $column_value;
$data = $data;

if ($this->debug == true) {
$query_to_execute = $this->show_query($sql, $data, $this->query_caveat);
}

$this->prepare_and_execute($sql, $data);
}



public function delete($id, $target_tbl = null) {

if (!isset($target_tbl)) {
Expand Down

0 comments on commit 990a50c

Please sign in to comment.