I am facing this issue. Appreciate any advices.
I have a file called home.php. This home.php will get data from a url parameter called user.
home.php
$u = $GET_["user"];
include('config.php');
Whenever ppl entered http://www.mydomain.com/index.php?user=hello, the text “hello” will be captured and put into variable $u.
I have a database called “hello” for that specific user. In the config.php i will do sql connection to the database using the following code.
Config.php
define('DB_NAME', $u);
define('DB_HOST', 'localhost');
define('DB_USERNAME', 'admin');
define('DB_PASSWORD', '123456');
$db = DB::getInstance();
//connect to database
$db->connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);
Database connection class
function connect($host, $username, $password, $database) {
mysql_connect($host, $username, $password) or die('Server connexion not possible.');
mysql_select_db($database) or die('Database connexion not possible.');
}
Above are all code snippets.
My issue is i keep getting Database connexion not possible error. I believe everything is logically correct. To debug this, whenever i replaced define(‘DB_NAME’, $u); with define(‘DB_NAME’, “Hello”); -> it works. It seems that i cannot dynamically use the value from $u.
thnk all. help appreciated.
You’re looking to use
$_GET– there is no such thing as$GET_