Skip to content

Commit

Permalink
converted for use wis PDO
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioWi committed Mar 9, 2018
1 parent fb57ac5 commit d303676
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
53 changes: 53 additions & 0 deletions server/inc/class/Db.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

class Db extends PDO {
private $smt;

public function __construct($options, $attributes) {
parent::__construct(SERVER, USER, PW, $options);
foreach ($attributes as $key => $value) {
$this -> setAttribute($value[0], $value[1]);
}
}

public function selectOne($query) {
//$stmt = $this -> $query($query);
$this -> $stmt = $this -> $query($query);
$result = $stmt -> fetch(FETCH);
return $result;
}

public function selectMultiple($query) {
$this -> $smt = $this -> $query($query);
$result = $this -> $smt -> fetchALL(FETCH);
return $result;
}

public function change($query){
return $this -> exec($query);
}

public function insert($query, $settings){
$stmt = $this -> prepare($query);
return $stmt -> execute($settings);
}

public function preparedStatement($query, $params){
$stmt = $this -> prepare($query);
for ($i = 0; $i <= count($params); $i++) {
$stmt -> execute($params[$i]);
}
//return $stmt;
}

public function run($sql, $args = NULL){
if (!$args){
return $this->query($sql);
}
$stmt = $this->prepare($sql);
$stmt->execute($args);
return $stmt;
}

}
?>
2 changes: 2 additions & 0 deletions server/inc/def/.htusers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test:$apr1$VPrYUJxG$GycWhfCu7rz7Q.sYCPnbA0
trackingdevice_submit:$apr1$NRGAA/fA$YvxRSc7mlRrRpriCBZfSY0
22 changes: 22 additions & 0 deletions server/inc/def/def.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// DB-Data
//define('SERVER', 'mysql:host=db;dbname=gpstracking');
define('SERVER', 'mysql:host=db;');
define('USER', 'gpstracking');
define('PW', 'myBADsecret');
define('FETCH', PDO::FETCH_ASSOC);

$options = array (
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
);
$attributes = array (
'case' => array(PDO::ATTR_CASE, PDO::CASE_NATURAL),
'error' => array(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
);

$database = 'gpstracking';
$mysql_table = 'gpsdata';

// other
date_default_timezone_set("UTC");
?>

0 comments on commit d303676

Please sign in to comment.