<commit_before><?php 

// include_once('db.php');

header('content_type: application/json');

$request = $_SERVER['REQUEST_METHOD'];

switch ($request) {
	case 'GET':
		 getMethod();
		break;
	case 'PUT':
		echo '{"name": "Put ... Rest Api"}';
		break;
	case 'POST':
		$data = json_decode(file_get_contents('php://input'),ture);
		postMethod($data);
		break;

	case 'DELETE':
		echo '{"name": "Delete ... Rest Api"}';
		break;
	default:
		# code...
		break;
}

function getMethod(){
	 include('db.php');

	$sql = "SELECT * FROM user";
	$result= mysqli_query($conn, $sql); 

	if (mysqli_num_rows($result)> 0) {
		$rows = array();

		while ($r = mysqli_fetch_assoc($result)) {
			$rows["result"] [] = $r ; 
		}
		echo json_encode($rows);
	}else{

		echo '{"result": "Data not found"}';
	}


}


function postMethod($data){
include('db.php');

$name = $data["name"];
$age = $data["age"];
$email=$data["email"];

$sql = "INSERT INTO user ( name, age, email, created_at) VALUES ('$name', '$age', '$email', NOW())";

if (mysqli_query($conn,$sql)) {
	echo '{"result": "data inserted"}';
}else {
	echo '{"result": "data not inserted"}';
}

}


?><commit_msg>update method created<commit_after><?php 

// include_once('db.php');

header('content_type: application/json');

$request = $_SERVER['REQUEST_METHOD'];

switch ($request) {
	case 'GET':
		 getMethod();
		break;
	case 'PUT':
		$data = json_decode(file_get_contents('php://input'),ture);
		putMethod($data);
		break;
	case 'POST':
		$data = json_decode(file_get_contents('php://input'),ture);
		postMethod($data);
		break;

	case 'DELETE':
		echo '{"name": "Delete ... Rest Api"}';
		break;
	default:
		# code...
		break;
}

// get data 


function getMethod(){
	 include('db.php');

	$sql = "SELECT * FROM user";
	$result= mysqli_query($conn, $sql); 

	if (mysqli_num_rows($result)> 0) {
		$rows = array();

		while ($r = mysqli_fetch_assoc($result)) {
			$rows["result"] [] = $r ; 
		}
		echo json_encode($rows);
	}else{

		echo '{"result": "Data not found"}';
	}


}

// inserted data 

function postMethod($data){
include('db.php');

$name = $data["name"];
$age = $data["age"];
$email=$data["email"];

$sql = "INSERT INTO user ( name, age, email, created_at) VALUES ('$name', '$age', '$email', NOW())";

if (mysqli_query($conn,$sql)) {
	echo '{"result": "data inserted"}';
}else {
	echo '{"result": "data not inserted"}';
}

}

// updated data 

function putMethod($data){
include('db.php');

$id = $data["id"];
$name = $data["name"];
$age = $data["age"];
$email=$data["email"];

$sql = "UPDATE user SET name = '$name', age ='$age', email = '$email', created_at= NOW() WHERE id ='$id'";

if (mysqli_query($conn,$sql)) {
	echo '{"result": "Updated succesfully"}';
}else {
	echo '{"result": " not Updated"}';
}

}



?>
{'fraction_non_alphanumeric': 0.2328519855595668, 'fraction_numerical': 0.0007220216606498195, 'mean_word_length': 4.422700587084149, 'pattern_counts': {'":': 11, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '755021', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1021, 'n_words': 238}