Fatal error: Class 'Connected' not found in C: xampp htdocs home.php on line 5

Asked

Viewed 977 times

1

I’m having this problem connecting with the bank

PHP:

$i = new Conexao();

$f = $imv['imovel_id'];

$i->ExecSQL("select * from imoveis_fotos where foto_imovel = '$f' limit 1");

$foto = $i->ListarDados();

PHP Conexão:

class Conexao {

private $host;
private $user;
private $senha;
private $bd;
private $link;
public  $query;
public  $lista;

//private $tabela;

/**
 *funcao construtora que inicia o link caso esteja null
 */
function __construct() {
    if ($this->link == NULL):

        $this->getConexao();    

    endif;


}

/*
 *faz a conexao caso não tenha valores no LINK
 */
public function getConexao() {
    $this->host = 'localhost';
    $this->user = 'root';
    $this->senha = '';
    $this->bd = 'imoveis';


    $this->link = mysql_connect($this->host, $this->user, $this->senha) or die('Erro de conexão');
    mysql_select_db($this->bd, $this->link);
    mysql_set_charset('UTF8', $this->link); 
}

PHP Config:

<?php


function __autoload($class) {

$arquivo = "{$_SERVER['DOCUMENT_ROOT']}/app/{$class}.class.php";

if (file_exists($arquivo)):
    //require_once (Config.php);
    require_once ($arquivo);
else:
    die("<h1>Erro algum arquivo esta faltando</h1>");

endif;
  • What version php?

  • PHP version 5.6.8

  • Avoid using mysql because it is obsolete, use mysqli or PDO, apparently is trying to include the class Conexao who is in C:\xampp\htdocs\home.php. Which directory is the file Conexao? In app msm?

  • Yes, this in Connexion

  • I don’t think you understand me... the file Conexao is in which folder (directory), this error is giving because the include or require is wrong, need to point to the correct file location.

  • C: xampp htdocs app Conexao.class.php

  • So the problem is in __autoload, that is not working properly. It does echo $_SERVER['DOCUMENT_ROOT'] and see what it shows, normally DOCUMENT_ROOT brings up to the root of the project which in your case is app. That is to say, C:\xampp\htdocs\app, then as you wrote /app/{$class}.class.php, the link to the archive was C:/xampp/htdocs/app/app/{$class}.class.php

  • Thank you very much.

  • Worked? If yes, I will turn the comment in response and you leave with the symbol of best answer (green).

Show 4 more comments

1 answer

1


So the problem is in __autoload, that is not working properly. Does echo $_SERVER['DOCUMENT_ROOT'] and see what it shows, normally DOCUMENT_ROOT brings up to the root of the project which in your case is app. That is to say, C:\xampp\htdocs\app, then as you wrote /app/{$class}.class.php, the link to the archive was C:/xampp/htdocs/app/app/{$class}.class.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.