move to PDO and seperate config file
This commit is contained in:
parent
8afeb860c9
commit
aabb35f932
|
@ -0,0 +1,13 @@
|
||||||
|
;<?php
|
||||||
|
;die();
|
||||||
|
;/*
|
||||||
|
|
||||||
|
dialect="mysql"
|
||||||
|
host="localhost"
|
||||||
|
user="web"
|
||||||
|
password=""
|
||||||
|
dbname="web"
|
||||||
|
charset="utf8mb4"
|
||||||
|
|
||||||
|
;*/
|
||||||
|
;?>
|
21
setup.php
21
setup.php
|
@ -1,13 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$conffile=parse_ini_file("config.ini.php");
|
||||||
|
|
||||||
|
$dsn=$conffile["dialect"].':host='.$conffile["host"].';dbname='.$conffile["dbname"].';charset='.$conffile["charset"];
|
||||||
|
|
||||||
$id=0;
|
$id=0;
|
||||||
if(!is_null($_GET["id"]) and is_numeric($_GET["id"])){
|
if(!is_null($_GET["id"]) and is_numeric($_GET["id"])){
|
||||||
$id=$_GET["id"];
|
$id=$_GET["id"];
|
||||||
}
|
}
|
||||||
$msql=new mysqli('localhost','web','','web');
|
try{
|
||||||
if($msql->connect_errno){
|
$pdo=new PDO($dsn,$conffile["user"],$conffile["password"]);
|
||||||
die("connection error: ".$msql->connect_error);
|
}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";
|
$string="SELECT id,file,title,hover FROM comics ORDER BY CASE WHEN (id=?) THEN 0 ELSE 1 END, id DESC";
|
||||||
$qry=$msql->query($string) or die($msql->error);
|
$qry=$pdo->prepare($string);
|
||||||
$comic=$qry->fetch_assoc();
|
$qry->execute([$id]);
|
||||||
|
$comic=$qry->fetch(PDO::FETCH_ASSOC);
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue