I made a config.php file which contains MySQL connection info.
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Cannnot connect!');
mysql_select_db(DB_NAME, $con) or die(mysql_error());
My question is how do I add it into a class?
<?php
require_once('config.php');
class users {
private $id;
public function __construct($id) {
global $con;
$sql = "MySQL script'";
$rs = mysql_query($sql) or die(mysql_error());
}
}
mysql_close($con);
This does not work, I know that I can make it like this:
private $id;
private $con;
public function __construct($id) {
$this->con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Cannnot connect!');
mysql_select_db(DB_NAME, $con) or die(mysql_error());
}.......
to make it work, but then config.php will be useless in this situation.
How to I global the variables from config.php in class?
Thanks.