generated from teknasyon-bootcamp/homework5
-
Notifications
You must be signed in to change notification settings - Fork 4
/
post-update.php
60 lines (49 loc) · 1.45 KB
/
post-update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require "vendor/autoload.php";
$config = require "config.php";
$engine = $config['engine'];
$host = $config['host'];
$user = $config['user'];
$pass = $config['password'];
$log_type = $config['logging'];
$log_file_dir = __DIR__."/storage/logs/logs.log";
use App\DB\Engine\Mysql;
use App\DB\Engine\MongoDB;
use App\Db\Database;
use App\Logger\Driver\Database as LoggerDatabase;
use App\Logger\Driver\File;
use App\Logger\Logger;
use App\Logger\LoggableInterface;
if ($engine == "mysql") {
$driver = new Mysql($host, $user, $pass, "book_app");
} elseif ($engine =="mongodb") {
$driver = new MongoDB("", "", "", "", "", []);
}
if($log_type =="file"){
$logger = new Logger(new File($log_file_dir));
}else{
$logger = new Logger(new LoggerDatabase($driver));
}
try{
$db = new Database();
$db->setDriver($driver);
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
$post_id = $_GET['id'];
$post = $_GET['post'];
try {
$is_updated = $db->update("posts",$post_id, [['post' => $post]]);
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
?>
<?php include "_shared/header.php";?>
<?php
if ($is_updated){
echo "<p class='text-center'>Post başarıyla güncellendi</p>";
echo "<br>";
echo "<div class='d-flex justify-content-center'><a href='http://localhost/homework5-hw5_grup3/index.php' class='btn btn-primary mt-5'>Anasayfaya geri dön</a></div>";
}
?>
<?php include "_shared/footer.php";?>