Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DBConnection {
- public $baza;
- public $user;
- public $pass;
- public $host;
- public $expr;
- public function __construct() {
- $this->baza = 'press';
- $this->user = 'root';
- $this->pass = '';
- $this->host = 'localhost';
- }
- public function connect() {
- try {
- $str = "mysql:host=$this->host;dbname=$this->baza";
- $this->expr = new PDO($str, $this->user, $this->pass);
- } catch (PDOException $ex) {
- echo "GRESKA SA KONEKCIJOM : " . $ex()->getMessage();
- }
- }
- public function __destruct() {
- $this->expr = null;
- }
- public function query($sql) {
- try {
- $rez = $this->expr->query($sql);
- $niz = $rez->fetchAll(PDO::FETCH_ASSOC);
- return $niz;
- } catch (PDOException $ex) {
- echo "GRESKA SA UPITOM: " . $ex()->getMessage();
- }
- }
- public function insert($sql) {
- try {
- $this->expr->beginTransaction();
- $this->expr->exec($sql);
- $this->expr->commit();
- } catch (PDOException $ex) {
- $this->expr->rollback();
- echo "GRESKA INSERT: " . $ex()->getMessage();
- }
- }
- public function delete($sql) {
- try {
- $this->expr->beginTransaction();
- $this->expr->exec($sql);
- $this->expr->commit();
- } catch (PDOException $ex) {
- $this->expr->rollback();
- echo "GRESKA DELETE: " . $ex()->getMessage();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement