So i am currently coding database connection class and i have encountered very strange behavior from my script.
base.class.php:
<?php
class base{
private $settings;
function get_settings(){
$settings["dbhost"] = 'localhost';
$settings["dbuser"] = '*****';
$settings["dbpass"] = '*****';
$settings["dbname"] = 'core';
return $settings;
}
}
?>
database.class.php
<?php
require_once 'base.class.php';
class database extends base{
private $query_now;
private $link;
public function __construct(){
$settings = base::get_settings();
$dbhost = $settings["dbhost"];
$dbuser = $settings["dbuser"];
$dbpass = $settings["dbpass"];
$dbname = $settings["dbname"];
$this->link = mysql_connect($dbhost, $dbname, $dbpass) or die ("Could not connect to the mysql database");
mysql_select_db($dbname, $this->link) or die ("Could not select the database");
}
function query($query){
$this->query_now = $query;
return mysql_query($query, $this->link);
}
function getArray($result){
return mysql_fetch_array($result);
}
}
?>
When i try to create an instance of database class, i get mysql_connect error. I have tried to echo my array and it seems that correct information is being passed over. Now the strange thing is if i remove my password from the base class i don't get a mysql_connect error but this time instead i get "Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'core'@'localhost' (using password: YES) " In case you are wondering, does my mysql database user has a password, the answer is: yes for sure... (Also i have tried to setup a simple script for connecting to my database and everything worked fine) So any ideas?