From aabb35f93216dcf2b1ead2073aeb08d64cac7caa Mon Sep 17 00:00:00 2001 From: "M. Gardner" Date: Sun, 28 Jul 2019 14:30:43 +0300 Subject: [PATCH] move to PDO and seperate config file --- config.ini.php | 13 +++++++++++++ setup.php | 21 ++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 config.ini.php diff --git a/config.ini.php b/config.ini.php new file mode 100644 index 0000000..fd406cd --- /dev/null +++ b/config.ini.php @@ -0,0 +1,13 @@ +; diff --git a/setup.php b/setup.php index f9235ac..4959762 100644 --- a/setup.php +++ b/setup.php @@ -1,13 +1,20 @@ connect_errno){ - die("connection error: ".$msql->connect_error); +try{ + $pdo=new PDO($dsn,$conffile["user"],$conffile["password"]); +}catch(\PDOException $e){ + throw new \PDOException($e->getMessage(), (int)$e->getCode()); } -$string="SELECT id,file,title,hover FROM comics ORDER BY CASE WHEN (id='$id') THEN 0 ELSE 1 END, id DESC"; -$qry=$msql->query($string) or die($msql->error); -$comic=$qry->fetch_assoc(); +$string="SELECT id,file,title,hover FROM comics ORDER BY CASE WHEN (id=?) THEN 0 ELSE 1 END, id DESC"; +$qry=$pdo->prepare($string); +$qry->execute([$id]); +$comic=$qry->fetch(PDO::FETCH_ASSOC); ?> \ No newline at end of file