Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7655205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:27:11+00:00 2026-05-31T12:27:11+00:00

I am working on a test class mostly to self teach. Below is the

  • 0

I am working on a test class mostly to self teach. Below is the class:

class Connection
{   
    public $con;
    public $dbSelected;
    public $activeConnection;
    public $dataBaseName;
    function __contruct($dbUserName, $dbPassword, $server = "localhost")
    {
        $this->con = mysql_connect($server,$dbUserName,$dbPassword);
        if(!$this->$con)
        {
            $this->activeConnection = false;
        }
        else
        {
            $this->activeConnection = true;
        }
    }

    public function dbConnect($dbName, $identifyer = null)
    {   
        if ($identifyer === null)
        {
            $identifyer = $this->con;
        }
        $this->dbSelected = mysql_select_db($dbName, $identifyer);
        $this->dataBaseName = $dbName;
        if($this->dbSelected != true)
        {
            $this->connectionErrorReport(__LINE__);
        }
    }


    public function cleanData( array $submission)
    {
        unset($submission["throughTheCleaners"]);
        foreach($submission as $key => $value)
        {

            if(is_array($value))
            {
                $data[$key] = $this->cleanData($value);
            }
            else
            {
                $data[$key] = mysql_real_escape_string($value);
            }
        }
        $data["throughTheCleaners"] = true;
        return $data;
    }


    public function query($query, $dataSent)
    {
        if($dataSent["throughTheCleaners"] != true)
        {
            die("you must clean the data".__LINE__);
        }

        if($this->activeConnection == true && $this->dbSelected == true)
        {
            $result = mysql_query($query) or queryErrorReport($query, __LINE__);
            $i = 0;
            while($row = mysql_fetch_array($result))
            {
                foreach($row as $key => $value)
                {
                    $data[$i][$key] = $value;
                    $i++;
                }
            }
            return $data;           
        }
        else
        {
            $this->$connectionErrorReport(__LINE__);
        }
    }   

    public function connectionErrorReport($line = __LINE__)
    {
        $error = "There has been a connection error on line ".$line."</br>";
        if($this->activeConnection == false)
        {
            $error.= "Active Connection Error <br/>";
        }
        if($this->dbSelected  == false)
        {
            $error.= "Data Base Selection Error <br/>";
        }
        die($error.mysql_error());
    }

    public function queryErrorReport($query, $line = __LINE__)
    {
        die("There was a query error on ".$line."<br />$query<br/>".mysql_error());
    }

    function __destruct() {
        mysql_close($this->con);
    }
}

I can not for the life of my figure out why it will not pick up the mysql database resourse stored in the $con variable during the contructor call and use it in other functions.

Eventually there will be an encryption function for strings in another class but the only errors I am currently getting fall on the connection class.

So the page throwing the error looks like this:

include 'connection.php';
include 'loginClass.php';
$longinConnection = new Connection('***USERNAMEHERE***','***PASSWORD***');
$longinConnection->dbConnect("***DBTOCONNECTTO***");
echo Authoriz::encryptPassword("***USERPASSWORD***",$longinConnection);

This page tests the encryptPassword function but I can’t even get the Connection class to work. The errors it throws are below:

Warning: mysql_select_db() expects parameter 2 to be resource, null given in [PATH] on line 27
There has been a connection error on line 31
Active Connection Error
Data Base Selection Error

Warning: mysql_close() expects parameter 1 to be resource, null given in [PATH] on line 103

It seems to me that the $con variable is not being set for some reason any insight into what I am doing wrong would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:27:13+00:00Added an answer on May 31, 2026 at 12:27 pm

    You misspelled __construct so it’s not firing when you initialize the class, and not initializing $this->con

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is this thing not working? [Database(Name=Relationships_Test)] [Table(Name = Order)] public class Order {
I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,
I've written this small test class just to illustrate my problem When working with
here is working java code class Cup { public String sayColor() { return i
Working with Test::Unit and Shoulda. Trying to test Users.create . My understanding is that
I have been working on test framework, which creates a new app domain to
I'm working on a test framework in Perl. As part of the tests, I
I am working on a test server with an Oracle 11g installed. I was
I'm working with Quick Test Professional 11. The situation is, i would like to
I have mocks working where I test that methods on my mocked object are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.