Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Author: Lukas Kusk Gjetting
- */
- $db = new Databasing(true); // Change parameter to correspond to whether or not I'm at home right now.
- class Databasing {
- protected $mysqli;
- public function __construct($athome) {
- $this->mysqli = $this->getConnected($athome);
- }
- function getCategories(){
- $query = "SELECT * FROM `categories`";
- $result = $this->mysqli->query($query);
- $array = $result->fetch_all();
- return $array;
- }
- function getExcercises($cat){
- $query = "SELECT * FROM `excercises` WHERE `cat_id` = " . $cat;
- $result = $this->mysqli->query($query);
- $array = $result->fetch_all();
- return $array;
- }
- function getConnected($athome) {
- if($athome){ // If I'm at home, use the XAMPP MySQL-credentials
- $host = "localhost";
- $db = "database";
- $user = "root";
- $pass = "";
- }else{ // If not, use the UnoEuro-ones
- $host = "mysql38.unoeuro.com";
- $db = "thedatabase_1";
- $user = "lukasgjetting";
- $pass = "password";
- }
- $mysqli = new mysqli($host, $user, $pass, $db);
- if($mysqli->connect_error) // Couldn't connect! Maybe I haven't changed the $athome parameter?
- die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
- return $mysqli;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement