Jump to content

Archived

This topic is now archived and is closed to further replies.

Ravi Kumar

problem with multiple mysal databases

Recommended Posts

Hi All

Here is my problem.

I have PHP 5 and MYSQL 4.1 installed on my server machine.

Now we want to upgrade to mysql 5.For this we have installed MySql 5.0 on one of our machines and
using this machine's ip address to connect to MySql.

Our application is behaving strangely.

It is pulling information from mysql 4 database in some pages which it shouldn't and in other pages it is pulling information from mysql 5 database though the ipaddress of the DBHOST is pointed to MYSQL 5.

We have cross checked all the configuration files and $DBHOST variable in connection class.

Please go through the below code snippet

class samplebl
{
        private $conn;

        function __construct()
        {
$this->conn = DbFactory::getWriter();
}

function __destruct()
{
DbFactory::close($this->conn);
}

        function getData()
        {
              //this is supposed to pull data from 172.16.*.*
              $result = mysql_query("select * from products");
        }
}


class DbFactory
{
        public static function getReader()
{
                //dbhost is pointing to mysql 5.0 on following address.Mysql 4 is on same machine.
return self::connect('172.16.*.*', 'root', '');
}

public static function getWriter()
{
return self::connect('172.16.*.*', 'root', '');
}

private static function connect($dbHost, $dbLogin, $dbPassw)
{
$conn = mysql_connect($dbHost, $dbLogin, $dbPassw);

if (!$conn)
{
  die('Could not connect: ' . mysql_error());
$conn = false;
}
else
{
;
}

return $conn;
}

public static function close($conn)
{
if ($conn)
{
mysql_close($conn);
}
}
}



Please help me on this.
Waiting for a response....

Ravi Kumar

Share this post


Link to post
Share on other sites
The mysql_*() functions have an optional "link identifier".  Adding that might fix your problem.

[code] mysql_query($query, $this->conn)[/code]

Share this post


Link to post
Share on other sites

×

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.