<?php

require_once "connection.php";
require_once "get.model.php";

class PutModel{


	static public function putData($table,$data,$id,$nameId){

		$response = GetModel::getDataFilter($table,$nameId,$nameId,$id);

		if(empty($response)){

			return null;
		}

		$set = "";

		foreach($data as $key => $value){

			$set .= $key." = :".$key.",";

		}

		$set = substr($set,0,-1);

		$sql = "UPDATE $table SET $set WHERE $nameId = :$nameId";

		$stmt = Connection::connect()->prepare($sql);

		foreach($data as $key => $value){

			$stmt ->bindParam(":".$key,$data[$key],PDO::PARAM_STR);
		}

		$stmt ->bindParam(":".$nameId,$id,PDO::PARAM_STR);

		if($stmt ->execute()){

			$response = array(

				"comment"=> "The process was successful"

			);

			return $response;

		}else {

			return Connection::connect()->errorInfo();

		}

	}


}
	


?>