Jump to content

Strange behavior


macross

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.