move to PDO and seperate config file

This commit is contained in:
M. Gardner 2019-07-28 14:30:43 +03:00
parent 8afeb860c9
commit aabb35f932
2 changed files with 27 additions and 7 deletions

13
config.ini.php Normal file
View File

@ -0,0 +1,13 @@
;<?php
;die();
;/*
dialect="mysql"
host="localhost"
user="web"
password=""
dbname="web"
charset="utf8mb4"
;*/
;?>

View File

@ -1,13 +1,20 @@
<?php
$conffile=parse_ini_file("config.ini.php");
$dsn=$conffile["dialect"].':host='.$conffile["host"].';dbname='.$conffile["dbname"].';charset='.$conffile["charset"];
$id=0;
if(!is_null($_GET["id"]) and is_numeric($_GET["id"])){
$id=$_GET["id"];
$id=$_GET["id"];
}
$msql=new mysqli('localhost','web','','web');
if($msql->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);
?>