2

I've installed PHP5.3.1 on top of 5.3.0 on my Windows 7 Pro laptop. I've installed Smarty, Pear and the relevant Pear packages. I use a config.php file to set up my development site on Win separately from my production sites which run on Linux. I've checked phpinfo and everything is set up correctly.

Now when I try and open up my Home page (login page) on 5.3.1, It thinks for about a minute, doesn't load, leaving a blank screen, and generates no errors. I've tried hiding parts of the config file and the stumbling block appears to be:

require_once "DB.php";
$db = DB::connect("mysql://root:$dbpass@$dbhost/$dbname") or die("unable to connect to $dbhost");
$db_hw = DB::connect( "mysql://root:$dbpass@$dbhosthw/egret" ) or die("unable to connect to $dbhost_hw");

My service uses two different database servers. I'm not even getting the die("") statements displaying.

Any suggestions as to what might be wrong?

George

René Höhle
  • 26,716
  • 22
  • 73
  • 82

1 Answers1

0

This is not working. In your case you overwrite the connection with the second connect. With mysql_connect or mysqli_connect you get a ressource back and you can handle your queries with the specified ressource:

How do you connect to multiple MySQL databases on a single webpage?

But when you use PEAR you access the same class DB::connect and this overwrites the db ressource and connection.

In your case you can call the disconnect() function before a new connection:

require_once "DB.php";
$db = DB::connect("mysql://root:$dbpass@$dbhost/$dbname") or die("unable to connect to $dbhost");
$db->disconnect();

$db = DB::connect( "mysql://root:$dbpass@$dbhosthw/egret" ) or die("unable to connect to $dbhost_hw");
Community
  • 1
  • 1
René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • I forgot to mention that my code had originally been: require_once "DB.php"; $db =& DB::connect("mysql://root:$dbpass@$dbhost/$dbname") or die("unable to connect to $dbhost"); $db =& DB::connect( "mysql://root:$dbpass@$dbhosthw/egret" ) or die("unable to connect to $dbhost_hw"); Which, I think, gets round that issue. – George Pitcher Nov 22 '12 at 15:21
  • When you call the class with &DB::connect you get the reference of the class. I think the best way is to close the connection before you call the second database. – René Höhle Nov 22 '12 at 15:41
  • The first connection uses $db as the resource and the second uses $db_hw. If I close the first connection in the config file, surely there will be no 'live' connection available to handle queries to that database? – George Pitcher Nov 22 '12 at 15:49
  • Yes correct when you want the first db reconnect to this database. Perhaps its easier when you use mysqli directly with prepared statements. – René Höhle Nov 22 '12 at 15:52
  • The current setup has been working fine on 5.3.0 on my laptop and 5.2.6 on the Linux server for almost 10 years, so I dont see that as the issue here. Unless something changed in the move from 5.3.0 to 5.3.1? – George Pitcher Nov 22 '12 at 15:55
  • Further testing has shown that the problem probably lies with the PEAR installation, as replacing DB with MDB2 produces the same symptoms. I tested the install by running the following: 'require once 'DB.php'; var_dump(class_exists('DB', false));' This gives me a 'bool(true)' result. I'm still stumped. I am about to upgrade my Linux server to PHP5.4.8 but am not doing it until I resolve this issue. – George Pitcher Nov 23 '12 at 08:47
  • Very strange but i had yesterday a site wich was noch running under 5.4.8 because a problem of the line endings. Very strange. This is wy i use at the moment wamp with 5.3.18. Perhaps load the latest php sources and upgrade your php version. Perhaps its working after that. – René Höhle Nov 23 '12 at 08:50