Going from a java background Learning php
I decided to use what i considered a good script to learn from for a connection cclass.

http://www.daniweb.com/code/snippet289.html

It works great for a single databsae but it is in mutliple database use I am having a few issues

I am writing a class file for each aspect of as sytem I am creating to learn php.
So for a booking system the member has a file, the location would have file etc with functions that add, remove, update etc.

Then you have your display pages that call the functions to display the outputs

Everything is working fine for apart from the multiple databse use

IF in cases you want to fetch an existing members list from another database you need to use the multidatabse feature

The host I have does not allow more then 1 sql socket so one database connection at a time so you open and close if you use 2.
I have done simple things before and that works fine using raw php sql connections in display pages etc.

the issue I have is that I use one fine, but then go to the another display page and it attempts to use the other database rather then the one you want.

So from the class from here I have 2 sql database connections case 0 and case 1.

Member class has function

function listMembers() {
            $this->log .= "listMembers Function Called<br />";
            $connection = new connectionFactory(1);
            $connection->ttl = 0;
            $connection->sql = "SELECT * FROM smf_members";
            $connection->getDataset();
            foreach($connection->data as $row) {
                $this->memberName = $row['memberName'];
                $this->memberClass = $row['class'];
                $this->memberBuild = $row['build'];
                echo ('<option name="' . $this->memberName . '"' . ' class="class_' . $this->memberClass . '">' . $this->memberName . ' [' . $this->memberBuild . ']' .  '</option>');
            }
        }

Selects case one, I have added a log feature to this file as well as extra to the database class file to see if it selects the right case it does
This works

But then if I have another page using another database for say an instance of something
the file has a function to list them

function getAllInstancesAdmin() {
            $connection = new connectionFactory(0);
            $connection->ttl = 0;
            $connection->sql = "SELECT * FROM instance";
            $connection->getDataset();
            echo $connection->log;
            //$connection->displayResultTable();
            echo $connection->connectionId;
            foreach($connection->data as $row) {
                $this->ins_id = $row['ins_id'];
                $this->instanceResult .=
                    '<tr>' .
                    '<td>' . $row['ins_name'] .  '</td>' . 
                '<td>' . $row['ins_location'] .  '</td>' . 
                '<td>' . $row['ins_info'] .  '</td>' . 
                '<td>' . $row['ins_size'] .  '</td>' .
                '<td>' .
                    '<input type="checkbox" name="ins_id" value="' . $this->ins_id . '" />' .
                    '</td>' .
                    '<td>' . '<a href="' . $this->outputPage . '?InstanceId=' . $row['ins_id'] . '">View</a>' .'</td>' .
                '<td>' . '<a href="' . $this->outputPage . '?InstanceId=' . $row['ins_id'] . '?Edit=true">Edit</a>' .'</td>' .
                '</tr>';
                exit();
            }

Which on its own also works fine
$connection = new connectionFactory(0); = case 0 or if i remove the 0 in the code it still selects the right case going on the log

So it selects the right case the log says In the connection class asking for
$connection->cnn_id;

Will output the right case so it does say it is using the case
But the of course It does not display the data (and since currently no error checking for the foreach()
there is an error

The log output says it has chosen case 0 rather then one but then the log says

doesn't exist
Becuase it is trying to find the instance table from the database holding the members so it is not changing the database

I also tried to change the databse class to if statments to just see if that did anything but did not
I also changed the line..
function db($cnn_id=0) {
to
function db($cnn_id) {
But had no effect

Any ideas why although it seems to select the right case it does not actually select the other database
Is it something to do with closing the old connection properly or something

Thanks in advance, may be silly but its a bit anoying :/

NM, Re-wrote it all even made my own db class folowing the lines of the linked one and it is working now it seems, made a couple of changes to the dbclass seems fine now.
Once I have done this project I will post some of the classes I made.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.