Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @copyright Galym Kerimbekov
- * @license GNU GPLv2
- */
- namespace MS\Core;
- use PDO;
- class ConfigModel {
- private $conndb = null;
- public function __construct() {
- $servername = null;
- $dbname = null;
- $username = null;
- $mysqlpassword = null;
- $BaseRoot = $_SERVER['DOCUMENT_ROOT'];
- $requestRoot = explode("/", dirname($_SERVER['REQUEST_URI']));
- if ($requestRoot['1'] === 'app') {
- $Baseurl = $BaseRoot;
- } else {
- $Baseurl = $BaseRoot . $requestRoot['1'];
- }
- if (file_exists("$Baseurl/app/Core/input.c.php")) {
- require "$Baseurl/app/Core/Configuration.php";
- try {
- $opt = array(PDO::ATTR_PERSISTENT => true,
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
- $this->conndb = new PDO("mysql:host=$servername;dbname=$dbname", $username, $mysqlpassword, $opt);
- } catch (PDOException $e) {
- print "Error!: " . $e->getMessage() . "";
- header("Location: app/Core/configure.php");
- }
- } else {
- header("Location: /");
- }
- }
- public function getConn() {
- return $this->conndb;
- }
- }
Add Comment
Please, Sign In to add comment