- Impact
- 38
Hey,
Been a year since I did OO php. Last time I used this I remember it working fine.. but..
My index.php
My dbcon.php
Now, last I checked, php is meant to automatically run __construct() when a new class is created. I created a new class of connection in the index file, but it does not run the __construct()
However, it works if I add: $connection->__construct(); to the index.php
Has something changed regarding this? Or am I being blind and missed something completely?
Been a year since I did OO php. Last time I used this I remember it working fine.. but..
My index.php
PHP:
<?php
include("includes/dbcon.php");
$connection = new connection();
?>
....
My dbcon.php
PHP:
<?php
class connection {
/* Main function
Connects to database
Die with error if fails to connect */
function __construct(){
/* Database Connection Varaiables */
$usrnme = "user";
$psswrd = "pass";
$servhst = "local";
$dbnme = "db";
$con = mysql_connect($servhst, $usrnme, $psswrd);
if (!$con)
{
die('Failed to connect: ' . mysql_error());
}
mysql_select_db($dbnme, $con);
}
}
?>
Now, last I checked, php is meant to automatically run __construct() when a new class is created. I created a new class of connection in the index file, but it does not run the __construct()
However, it works if I add: $connection->__construct(); to the index.php
Has something changed regarding this? Or am I being blind and missed something completely?