Exemplo n.º 1
0
 public function update(array $input)
 {
     if ($this->secure == true && isset($input['password'])) {
         $s = new Secure();
         $input['password'] = $s->make($input['password']);
     }
     // pull keys from assoc array
     $fields = array_keys($input);
     // pull values from assoc array
     $this->values = array_values($input);
     // Check if table has been chosen, if not return a string telling them to choose one!
     if (!isset($this->table)) {
         return "Please choose a table first using the selectTable function.";
     }
     $sql = "UPDATE " . $this->table . " SET ";
     if (count($fields) == 1) {
         $sql .= $fields[0] . "= ?";
     } else {
         for ($i = 0; $i < count($fields) - 1; $i++) {
             $sql .= $fields[$i] . "= ?, ";
         }
         $sql .= $fields[count($fields) - 1] . "= ?";
     }
     if ($this->timestamps == true) {
         $sql .= ", updated_at = now()";
     }
     $this->sql = $sql;
     return $this;
 }