no. the mssql_connection will be executed always.
I remembered here, you can always use the persitent database connection methods =p
mysql_pconnect()
mssql_pconnect()
odbc_pconnect()
MORE INFO HERE
Code:
<?
class database
{
public static $connected = false;
static function connect_db()
{
if(!self::$connected)
{
$link = odbc_pconnect("DRIVER={SQL Server}; SERVER=.\SQLEXPRESS; DATABASE=PTEmu;", "sa","123456");
if($link)
self::$connected = true;
}
echo self::$connected;
}
}
class use_db extends database
{
function __construct()
{
if(!parent::$connected)
{
echo "database not connected, connecting...";
parent::connect_db();
echo "database methods";
}
else
{
echo "database connected, methods here";
}
}
}
$v = new use_db;
?>
This class isnot very fancy, I made it now, but its good for you to learn inheritance in php, which is very important.
its been a while that I stopped with PHP, $connected will always be false everytime you refresh the page, so it'll always show the "database not connected" message.
My goal is force you to learn PHP or whichever language. I will not provide a "ready to go code".
With non-static methods I have to create a class instance like:
$instance = new myClass;
$instance->myNonStaticFunc();
With static methods the need to create a class instance is gone.
myClass::myStaticMethod();