-1
I can’t connect to my database, I have no errors, the connection just doesn’t happen, just gives me a blank page. I have these 4 small files responsible for Conn.
init.php:
<?php
session_start();
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => 'pass',
'db' => 'ooplr'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
spl_autoload_register(function($class) {
require_once ('classes/' .$class. '.php');
});
require_once ('functions/sanitize.php');
?>
config.php:
<?php
class Config {
public static function get($path = null) {
if($path) {
$config = $GLOBALS['config'];
$path = explode('/', $path);
foreach ($path as $bit) {
if(isset($config[$bit])) {
$config = $config[$bit];
}
}
return $config;
}
return false;
}
}
?>
DB.php
<?php
class DB {
private static $_instance = null;
private $_pdo,
$_query,
$_error = false,
$_results,
$_count = 0;
public function _construct() {
try {
$this->_pdo = new PDO('mysql:host=' .Config::get('mysql/host'). ';dbname=' .Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
} catch (PDOException $e) {
die($e->getMessage());
}
echo ('connected');
}
public static function getInstance() {
if(!isset(self::$_instance)) {
self::$_instance = new DB();
}
return self::$_instance;
}
}
?>
index php.
<?php
require_once('core/init.php');
DB::getInstance();
?>
That’s what it was all about.
– Miguel
Just one more comment: all magic methods are prefixed with two underscores: _call, __set, __get, etc.
– Rodrigo Rigotti
Okay understood, I didn’t know that obgado people
– Miguel