
		tmello
		
		(usa Debian)
		
		Enviado em 25/06/2014 - 23:26h 
		Olá galera estou começando agora com programação orientada, e estou tendo algumas dificuldades.
Abaixo mostrarei meu código seguido da mensagem de erro, gostaria que a galera me ajudasse a ter meu inside, para resolver o problema.
Arquivo "connection.class.php"
<?php
class conectar {
	private function conexao() {
		try{
			$pdo=new PDO("mysql:host=localhost;dbname=graciafinal;","root","root");
		}
		catch(PDOException $e){
			echo $e->getMessage()."<br />\n";
			echo $e->getLine()."<br />\n";
		}
		return $pdo;
	}
}
?>
Arquivo "ranking.class.php"
1 <?php
2	include "connection.class.php";
3	class rankings extends conectar{
4	
5	public function rankingGeral($orderby = NULL, $limite = NULL){
6	try{
7		$pdo=conexao();
8		$ranking=$pdo->prepare("SELECT * FROM characters ORDER BY {$orderby} DESC LIMIT {$limite}");
9		$ranking->execute();
10		$mostrar=$ranking->fetchAll(PDO::FETCH_OBJ);
11		foreach($mostrar as $mostrar_r){
12			echo $mostrar_r->pvpkills." - ".$mostrar_r->pvpkills;
13		}
14	}
15	catch(PDOExeption $err){
16			echo $err->getMessage()."<br />\n";
17			echo $err->getLine()."<br />\n";
18	}
19		return $ranking;
20	}
21
22 }
23
24	$rk=rankingGeral("pvpkills", 3);
25	echo $rk;
26 ?>
O navegador me retorna o seguinte erro.
Fatal error: Call to undefined function rankingGeral() in C:\AppServ\www\ranking.class.php on line 24
Alguém por favor poderia me dar um help para que eu possa encontrar e entender o que faz gerar este erro?
---------------
Edit: Problema resolvido ! HAHAHAHA vlw amigo Paulo Dias jr
Segue os respectivos códigos alterados.
Arquivo "connection.class.php"
<?php
class conectar {
	 protected $db;
        
        function __construct()
        {
            try 
            {
                    $this->db = new PDO("mysql:host=localhost;dbname=graciafinal", "root", "xd4ever");
            } 
            catch (PDOException $e) 
            {
                print "Error: " . $e->getMessage() . " <br/>";
                die();
            }
        }
        
        function __destruct() 
        {
                $this->disconnect();
                foreach ($this as $key => $value) 
                {
                    unset($this->$key);
                }
        }
        
        public function disconnect()
        {
            $this->db = null;
        }
}
?>
Arquivo "ranking.class.php"
<?php
	include "connection.class.php";
	
	class rankings extends conectar{
	public function rankingGeral($orderby = NULL, $limite = NULL){
		$pdo = $this->db;
		$ranking=$pdo->prepare("SELECT * FROM characters ORDER BY {$orderby} DESC LIMIT {$limite}");
		$ranking->execute();
		$mostrar=$ranking->fetchAll(PDO::FETCH_OBJ);
		foreach($mostrar as $mostrar_r){
			echo $mostrar_r->pvpkills." - ".$mostrar_r->pkkills;
		}
		
		return $ranking->execute();
		self::__destruct();
		$pdo = null;
	}
}
	
	$rk= new rankings();
	$rk->rankingGeral("pvpkills", 3);
?>