Jump to content

A small Error


RaajKumar

Recommended Posts

Fatal error: Call to a member function prepare() on a non-object in /home/u305527363/public_html/UCP/inc/Config.class.php on line 190

Line 190

$q = self::$g_con->prepare('SELECT groupName,groupID,groupRankName1,groupRankName2,groupRankName3,groupRankName4,groupRankName5,groupRankName6 FROM groups');

Can Anyone Help me pls :/

Edited by RaajKumar
Link to comment
Share on other sites


<?php
class Config {
private static $instance;
public static $g_con;
public static $_url = array();
private static $_pages = array(
'login','online','profile','logout','factions','faction','banlist','staff','changepass','changeemail','recover','signature','search','forum' , 'stats', 'top', 'refe', 'logs', 'referral', 'htop'
);
public static $factions = array();
public static $jobs = array();
public static $_PAGE_URL = 'http://localhost/rpg2/';
private static $_perPage = 30;
public static $_IP = 'blue.bugged.ro';

private function __construct() {
$db['mysql'] = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'rpg'
);

try {
self::$g_con = new PDO('mysql:host='.$db['mysql']['host'].';dbname='.$db['mysql']['dbname'].';charset=utf8',$db['mysql']['username'],$db['mysql']['password']);
self::$g_con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$g_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
error_log($e->getMessage());
}
self::_getUrl();
self::arrays();
}

public static function init()
{
if (is_null(self::$instance))
{
self::$instance = new self();
}
return self::$instance;
}

public static function isLogged() {
return isset($_SESSION['awm_user']) ? true : false;
}

private static function _getUrl() {
$url = isset($_GET['page']) ? $_GET['page'] : null;
$url = rtrim($url, '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
self::$_url = explode('/', $url);
}

public static function getContent() {
if(self::$_url[0] === 'action' && file_exists('inc/actions/' . self::$_url[1] . '.a.php')) { include 'inc/actions/' . self::$_url[1] . '.a.php'; return; }
if(isset(self::$_url[0]) && self::$_url[0] === 'signature') include_once 'inc/pages/signature.p.php'; ;
include_once 'inc/header.inc.php';

if(in_array(self::$_url[0],self::$_pages))
include 'inc/pages/' . self::$_url[0] . '.p.php';
else
include_once 'inc/pages/index.p.php';

include_once 'inc/footer.inc.php';
}

public static function rows($table,$id = '*') {
if(is_array($table)) {
$rows = 0;
foreach($table as $val) {
$q = self::$g_con->prepare("SELECT ".$id." FROM `".$val."`");
$q->execute();
$rows += $q->rowCount();
}
return $rows;
}
$q = self::$g_con->prepare("SELECT ".$id." FROM `".$table."`");
$q->execute();
return $q->rowCount();
}

public static function getPlayerData($id,$data) {
$q = self::$g_con->prepare("SELECT `".$data."` FROM `playeraccounts` WHERE `playerID` = '$id'");
$q->execute();
if($q) {
$udata = $q->fetch();
return $udata[$data];
}
else return 0;
}

public static function isActive($active) {
if(is_array($active)) {
foreach($active as $ac) {
if($ac === self::$_url[0]) return ' class="active"';
}
return;
} else return self::$_url[0] === $active ? ' class="active"' : false;
}

public static function isAjax() {
if(!self::isLogged()) return false;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
return true;
}
return false;
}

public static function _pagLimit() {
if(!isset(self::$_url[2]))
self::$_url[2] = 1;
return "LIMIT ".((self::$_url[2] * self::$_perPage) - self::$_perPage).",".self::$_perPage;
}

public static function _pagLinks($rows) {
if(!isset(self::$_url[2]))
self::$_url[2] = 1;
$adjacents = "2";
$prev = self::$_url[2] - 1;
$next = self::$_url[2] + 1;
$lastpage = ceil($rows/self::$_perPage);
$lpm1 = $lastpage - 1;

$pagination = "<div class='pagination dark'>";
if($lastpage > 1)
{
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == self::$_url[2])
$pagination.= "<a class='page gradient active' href='#'>$counter</a>";
else
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$counter'>$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if(self::$_url[2] < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == self::$_url[2])
$pagination.= "<a class='page gradient active' href='#'>$counter</a>";
else
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$counter'>$counter</a>";
}
$pagination.= "<a class='page gradient active' href='#'>...</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$lpm1'>$lpm1</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$lastpage'>$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > self::$_url[2] && self::$_url[2] > ($adjacents * 2))
{
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/1'>1</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/2'>2</a>";
$pagination.= "<a class='page gradient active' href='#'>...</a>";
for ($counter = self::$_url[2] - $adjacents; $counter <= self::$_url[2] + $adjacents; $counter++)
{
if ($counter == self::$_url[2])
$pagination.= "<a class='page gradient active' href='#'>$counter</a>";
else
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$counter'>$counter</a>";
}
$pagination.= "<a class='page gradient active' href='#'>...</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$lpm1'>$lpm1</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$lastpage'>$lastpage</a>";
}
else
{
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/1'>1</a>";
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/2'>2</a>";
$pagination.= "<a class='page gradient active' href='#'>...</a>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == self::$_url[2])
$pagination.= "<a class='page gradient active' href='#'>$counter</a>";
else
$pagination.= "<a class='page gradient' href='".self::$_PAGE_URL.self::$_url[0]."/page/$counter'>$counter</a>";
}
}
}
}
return $pagination .= '</div>';
}

private static function arrays() {
$lname = array(
'Civil','L.S.P.D','NG','F.B.I','Hitman','NR','Taxi','Aztecas','Ballas','Grove','Vagos','S.I'
);
$q = self::$g_con->prepare('SELECT groupName,groupID,groupRankName1,groupRankName2,groupRankName3,groupRankName4,groupRankName5,groupRankName6 FROM groups');
$q->execute();
self::$factions[0]['name'] = 'Civil';

while($row = $q->fetch(PDO::FETCH_OBJ)) {
self::$factions[$row->groupID]['name'] = $row->groupName;
self::$factions[$row->groupID]['lname'] = $lname[$row->groupID];
self::$factions[$row->groupID]['rank'] = array(0 => 'None',
1 => $row->groupRankName1, 3 => $row->groupRankName3, 5 => $row->groupRankName5,
2 => $row->groupRankName2, 4 => $row->groupRankName4, 6 => $row->groupRankName6,
);
}

$q = self::$g_con->prepare('SELECT jobName,jobID FROM jobs');
$q->execute();
self::$jobs[0] = 'None';
while($row = $q->fetch(PDO::FETCH_OBJ)) self::$jobs[$row->jobID] = $row->jobName;

}

}
?>

 

Edited by RaajKumar
Link to comment
Share on other sites

This is definitely not a small problem.

 

First off, your class does way, way too much. It seems you're using it as a god object where you put absolutely every feature you need in your application. That's not how OOP works. One class is supposed to have one specific purpose. So the first step is to separate your monster class into multiple simple classes.

 

Then your error handling is fudged up. Instead of simply leaving the PDO exceptions alone so that PHP can log them and stop the script, you catch the exceptions, log only the message (what about the file, line number, stack strace?) and then continue the script. This obviously makes no sense. If you continue with a failed database connection, you'll get nothing but nonsense -- like your non-object error.

 

There are other problems, but let's start with those two.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.