<?php
class Database {
public $isConn;
protected $datab;
// connect to db
public function __construct($options = []) {
$this->isConn = TRUE;
$decodedData = $this->df();
$mysqlConfig = $decodedData['mysql'];
try {
$username = $options['ajansyazili_otelv7'] ?? $mysqlConfig['kullanici_adi'];
$password = $options['ajansyazili_otelv7'] ?? $mysqlConfig['sifre'];
$host = $options['localhost'] ?? $mysqlConfig['host'];
$dbname = $options['dbname'] ?? $mysqlConfig['db'];
$this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
$this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->datab->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
// disconnect from db
public function Disconnect() {
$this->datab = NULL;
$this->isConn = FALSE;
}
// get rowv1_site
public function getRow($query, $params = []){
try {
$stmt = $this->datab->prepare($query);
$stmt->execute($params);
return $stmt->fetch();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
// get rows
public function getRows($query, $params = []){
try {
$stmt = $this->datab->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
// insert row
public function insertRow($query, $params = []){
try {
$stmt = $this->datab->prepare($query);
$stmt->execute($params);
return TRUE;
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function df() {
$decodedData = [
'mysql' => [
'host' => 'localhost',
'kullanici_adi' => 'DB KULLANICI ADI',
'sifre' => 'DB ŞİFRE',
'db' => 'DB VERİ TABANI ADI',
],
'hatirla' => [
'cookie_ismi' => 'hash',
'cookie_bitis' => 604800,
],
'session' => [
'session_ismi' => 'kullanici',
'token_ismi' => 'token',
],
];
return $decodedData;
}
// insert yeni kolon
public function kolon($query, $params = []){
try {
$stmt = $this->datab->prepare($query);
$stmt->execute();
return TRUE;
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
// update row
public function updateRow($query, $params = []){
$this->insertRow($query, $params);
}
// delete row
public function deleteRow($query, $params = []){
$this->insertRow($query, $params);
}
public function tabloAc($query)
{
try {
$stmt = $this->datab->exec($query);
} catch (PDOException $e) {
$e->getMessage();
throw new Exception($e->getMessage());
}
}
public function tabloSil($query)
{
try {
$stmt = $this->datab->exec($query);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
public function seo($s) {
$tr = array('ş','Ş','ı','I','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç','(',')','/',':',',');
$eng = array('s','s','i','i','i','g','g','u','u','o','o','c','c','','','-','-','');
$s = str_replace($tr,$eng,$s);
$s = strtolower($s);
$s = preg_replace('/&amp;amp;amp;amp;amp;amp;amp;amp;.+?;/', '', $s);
$s = preg_replace('/\s+/', '-', $s);
$s = preg_replace('|-+|', '-', $s);
$s = preg_replace('/#/', '', $s);
$s = str_replace('.', '', $s);
$s = str_replace('+', 've', $s);
$s = str_replace('&', 've', $s);
$s = str_replace('*', '-yildiz-', $s);
$s = str_replace('?', '', $s);
$s = str_replace('\'', '-', $s);
$s = str_replace(array('”','“','"'), '', $s);
$s = str_replace("’", "", $s);
$s = str_replace("´", "", $s);
$s = trim($s, '-');
return $s;
}
}
?>