1

I have following code, however $email is not getting printed on page. I don't know why.

<?php


    $email = "myemil@gmail.com";        
    $tag = "login";

    require_once 'DB_Functions.php';
    $db = new DB_Functions();

    echo $email; 
?>

If I remove

require_once 'DB_Functions.php'; $db = new DB_Functions();

then it prints email on page. Why is this happening? I want to connect to DB. Please help.

Above code file is on godaddy server, in a subdomain.

DB_Functions.php looks like

class DB_Functions {

private $db;
 function __construct() {
    require_once 'DB_Connect.php';
    $this->db = new DB_Connect();
    $this->db->connect();
}

function __destruct() {

} 

}

DB_Connect looks like

class DB_Connect {

// constructor
function __construct() {

}

// destructor
function __destruct() {
    // $this->close();
}

// Connecting to database
public function connect() {
    require_once 'config.php';
    // connecting to mysql
    $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    // selecting database
    mysql_select_db(DB_DATABASE);

    // return database handler
    return $con;
}

// Closing database connection
public function close() {
    mysql_close();
}   

}

config.php

define("DB_HOST", "localhost"); define("DB_USER", "db1"); define("DB_PASSWORD", "db1"); define("DB_DATABASE", "db1");

Kaustubh
  • 653
  • 6
  • 21

0 Answers0