SHARE
TWEET

db-connection.php

a guest Jan 25th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * Author: Lukas Kusk Gjetting
  4. */
  5.  
  6. $db = new Databasing(true); // Change parameter to correspond to whether or not I'm at home right now.
  7.  
  8. class Databasing {
  9.     protected $mysqli;
  10.  
  11.     public function __construct($athome) {
  12.  
  13.         $this->mysqli = $this->getConnected($athome);
  14.  
  15.     }
  16.  
  17.     function getCategories(){
  18.         $query = "SELECT * FROM `categories`";
  19.  
  20.         $result = $this->mysqli->query($query);
  21.         $array = $result->fetch_all();
  22.  
  23.         return $array;
  24.     }
  25.  
  26.     function getExcercises($cat){
  27.         $query = "SELECT * FROM `excercises` WHERE `cat_id` = " . $cat;
  28.  
  29.         $result = $this->mysqli->query($query);
  30.         $array = $result->fetch_all();
  31.  
  32.         return $array;
  33.     }
  34.  
  35.     function getConnected($athome) {
  36.  
  37.         if($athome){ // If I'm at home, use the XAMPP MySQL-credentials
  38.             $host = "localhost";
  39.             $db = "database";
  40.             $user = "root";
  41.             $pass = "";
  42.         }else{      // If not, use the UnoEuro-ones
  43.             $host = "mysql38.unoeuro.com";
  44.             $db = "thedatabase_1";
  45.             $user = "lukasgjetting";
  46.             $pass = "password";    
  47.         }
  48.         $mysqli = new mysqli($host, $user, $pass, $db);
  49.  
  50.         if($mysqli->connect_error) // Couldn't connect! Maybe I haven't changed the $athome parameter?
  51.             die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
  52.  
  53.         return $mysqli;
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top