guys i have the following , relatively simple connection script to a database : [The code is clean , so don’t worry . ]
The below script is just creating a generic interface :
[CODE]
<?php
//Filename: IConnectInfo.php
interface IConnectInfo
{
const HOST =”localhost”;
const UNAME =”root”;
const PW =””;
const DBNAME = “login”;
public static function doConnect();
}
?>
The script below, that makes use of the above interface:
[CODE]
<?php
//FILENAME :: UniversalConnect.php
ini_set(“display_errors”,”1″);
ERROR_REPORTING( E_ALL | E_STRICT );
include_once(‘IConnectInfo.php’);
class UniversalConnect implements IConnectInfo
{
private static $server=IConnectInfo::HOST;
private static $currentDB= IConnectInfo::DBNAME;
private static $user= IConnectInfo::UNAME;
private static $pass= IConnectInfo::PW;
private static $hookup;
public static function doConnect()
{
self::$hookup=mysqli_connect(self::$server, self::$user, self::$pass, self::$currentDB);
if(self::$hookup)
{
echo “Successful connection to MySQL:<br/>”;
}
elseif (mysqli_connect_error(self::$hookup))
{
echo(‘Here is why it failed: ‘ . mysqli_connect_error());
}
return self::$hookup;
}
}
?>
now till here everything is neat and clean and works fine :
i tested the above two files are working , by adding the following 2 lines at the end of the above file .
[CODE]
$instance = new UniversalConnect();
$instance::doConnect();
I get a message “Successful connection to MySQL:” , perfect !!!
now comes the 3rd file : (I have commented out some of the code to make things simple) :
[CODE]
<?php
//FILENAME DataEntry.php
require_once(‘tablework/UniversalConnect.php’);
class DataEntry
{
//Variable for MySql connection
private $hookup;
private $sql;
private $tableMaster;
//Field Variables
private $name;
private $email;
private $lang;
public function __construct()
{
//Get table name and make connection
$this->tableMaster=”basics”;
if($this->hookup=UniversalConnect::doConnect()){
echo “<b>connected</b>”;
}else{
echo “<b>Not connected</b>”;
}
}
}
$instance = new DataEntry();
?>
now when i run the above file , somehow the connection to the database fails ! even though in UniversalConnect.php the connection is successful !
The error i get is
Here is why it failed: php_network_getaddresses: getaddrinfo failed: No such host is known. Not connected.
I really don’t understand why when the connection is made in UniversalConnect.php and the same connection is being returned to dataEntry.php , does the connection Fail ! .
I would appreciate any help .
Thank you .
Tenali .