· 9 years ago · Jan 23, 2017, 02:20 PM
1 // Function to update row in database
2 public function update($table,$params=array(),$where){
3 // Check to see if table exists
4 if($this->tableExists($table)){
5 // Create Array to hold all the columns to update
6 $args=array();
7 foreach($params as $field=>$value){
8 // Seperate each column out with it's corresponding value
9 $args[]=$field.'="'.$value.'"';
10 }
11 // Create the query
12 $sql='UPDATE '.$table.' SET '.implode(',',$args).' WHERE '.$where;
13 // Make query to database
14 $this->myQuery = $sql; // Pass back the SQL
15 if($query = $this->myconn->query($sql)){
16 array_push($this->result,$this->myconn->affected_rows);
17 return true; // Update has been successful
18 }else{
19 array_push($this->result,$this->myconn->error);
20 return false; // Update has not been successful
21 }
22 }else{
23 return false; // The table does not exist
24 }
25 }