- Mesajlar
- 600
Arkadaşlar aşağıdaki kodu localhostta çalıştırıyorum ama host a yüklediğimde sayfa hiç açılmıyor ve 500 diye bir hata veriyor. Sorun nedir anlayamadım tam olarak.
<?php
include "../models/ClientRepository.php";
$db = new PDO("mysql:host=localhost;dbname=ornek", "ornek", "mysql");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$method = $_SERVER["REQUEST_METHOD"];
$clients = new ClientRepository($db);
switch($method) {
case "GET":
echo json_encode($clients->getAll());
break;
case "POST":
echo json_encode($clients->insert(array(
name => $_POST["name"],
age => intval($_POST["age"]),
address => $_POST["address"],
married => $_POST["married"] === "true" ? 1 : 0
)));
break;
}
header("Content-Type: application/json");
?>
<?php
include "../models/ClientRepository.php";
$db = new PDO("mysql:host=localhost;dbname=ornek", "ornek", "mysql");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$method = $_SERVER["REQUEST_METHOD"];
$clients = new ClientRepository($db);
switch($method) {
case "GET":
echo json_encode($clients->getAll());
break;
case "POST":
echo json_encode($clients->insert(array(
name => $_POST["name"],
age => intval($_POST["age"]),
address => $_POST["address"],
married => $_POST["married"] === "true" ? 1 : 0
)));
break;
}
header("Content-Type: application/json");
?>