second part of my script wont run....

i'm lost here, I know that i can get data from both databases, i've commented out the both "half's" of the script just to see if my $display_block actually works, and it does...i get data from either database when i'm just pulling one at a time.

But when try to get data at the same time in one pass....i only get data from 'NYTD' and not from my "seadb" connection...

is this a flow issue? its seem like the second half of the script is never being parsed... I know this because i added just a generic ' echo "php parsed the second half" towards the bottom of the script...and it doesnt display
<?php
# header("Content-Type: text/xml");
#echo "<stats> \n";
 
 
$bg_test = 2;
 
$hostname_nydb = "localhost";
$database_nydb = "nytd";
$username_nydb = "root";
$password_nydb = "";
$nytddbcon = mysqli_connect("$hostname_nydb", "$username_nydb", "$password_nydb", "$database_nydb");
$hostname_seadb = "sysdb1";
$database_seadb = "nytd";
$username_seadb = "stats";
$password_seadb = "stats";
$seadbcon = mysqli_connect("$hostname_seadb", "$username_seadb", "$password_seadb", "$database_seadb");
 
if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
} else {
        $SERVERS = file('lists/wwwgslb.list');
        foreach($SERVERS as $SERVER) {
        $SRV = rtrim($SERVER);
#       echo $SRV;
 
        $nytdsql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
 
        $seasql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
        #$sql = "SELECT * FROM stats_page where server_name = 'web%t'";
#       echo $sql;
        #$sql = "SELECT * FROM host";
                mysql_select_db($database_nydb);
        $nytdres = mysqli_query($nytddbcon, $nytdsql);
 
        if ($nytdres) {
                while ($newArray = mysqli_fetch_array($nytdres, MYSQLI_ASSOC)) {
                  $id  = $newArray['id'];
                  $hostname = $newArray['description'];
                  $load1 = $newArray['load1'];
                  $cpu_idle = $newArray['cpu_idle'];
                  $connections = $newArray['connections'];
                  $hostname = $newArray['description'];
                  $no_hits = $newArray['hits'];
                  $diff_hits = $newArray['diff_hits'];
                  $hitsper = $newArray['hitsper'];
                  $hitspersec = sprintf("%.0f", $hitsper);
                  $dl_time = $newArray['dl_time'];
                  $date = $newArray['date'];
                  $swap_avail = $newArray['swap_avail'];
                  $swap_total = $newArray['swap_total'];
                  $result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
                  #$result_swap =  ( $swap_avail / $swap_total * 100);
                  $real_avail = $newArray['real_avail'];
                  $real_total = $newArray['real_total'];
                  $result_real = sprintf("%.0f", $real_avail / $real_total * 100);
if (($bg_test % 2) == 0){
        $BGCOLOR = "FFFFFF";
        }
else {
        $BGCOLOR = "cccccc";
        }
 
$bg_test++;
 
echo $display_block =
"
    <server>
        <id>$id</id>
        <name>$hostname</name>
        <load>$load1</load>
        <cpuidle>$cpu_idle</cpuidle>
        <memfree>$result_real</memfree>
        <swapfree>$result_swap</swapfree>
        <numconns>$connections</numconns>
        <hitspersec>$hitspersec</hitspersec>
        <numhits>$no_hits</numhits>
        <dltime>$dl_time</dltime>
        <lastupdated>$date</lastupdated>
    </server>
 
"; 
}
       } else {
              printf("Could not retrieve records: %s\n", mysqli_error($nytddbcon));
       }
}
##--------------------------------------------------------------------------------
## start of the seatle pull/display
##------------------------------------------------------------------------------
           mysql_select_db($database_seadb);
       $seares = mysqli_query($seadbcon, $seasql);
 
        if ($seares) {
                while ($newArray1 = mysqli_fetch_array($seares, MYSQLI_ASSOC)) {
                  $id  = $newArray1['id'];
                  $hostname = $newArray1['description'];
                  $load1 = $newArray1['load1'];
                  $cpu_idle = $newArray1['cpu_idle'];
                  $connections = $newArray1['connections'];
                  $hostname = $newArray1['description'];
                  $no_hits = $newArray1['hits'];
                  $diff_hits = $newArray1['diff_hits'];
                  $hitsper = $newArray1['hitsper'];
                  $hitspersec = sprintf("%.0f", $hitsper);
                  $dl_time = $newArray1['dl_time'];
                  $date = $newArray1['date'];
                  $swap_avail = $newArray1['swap_avail'];
                  $swap_total = $newArray1['swap_total'];
                  $result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
                  #$result_swap =  ( $swap_avail / $swap_total * 100);
                  $real_avail = $newArray1['real_avail'];
                  $real_total = $newArray1['real_total'];
                  $result_real = sprintf("%.0f", $real_avail / $real_total * 100);
if (($bg_test % 2) == 0){
        $BGCOLOR = "FFFFFF";
        }
else {
        $BGCOLOR = "cccccc";
        }
 
$bg_test++;
 
echo $display_block =
"
    <server>
        <id>$id</id>
        <name>$hostname</name>
        <load>$load1</load>
        <cpuidle>$cpu_idle</cpuidle>
        <memfree>$result_real</memfree>
        <swapfree>$result_swap</swapfree>
        <numconns>$connections</numconns>
        <hitspersec>$hitspersec</hitspersec>
        <numhits>$no_hits</numhits>
        <dltime>$dl_time</dltime>
        <lastupdated>$date</lastupdated>
    </server>
 
"; 
}
       } else {
               printf("Could not retrieve records: %s\n", mysqli_error($seadbcon));
       }
}
 
       mysqli_free_result($nytdres);
                mysqli_free_result($seares);
        mysqli_close($nytddbcon);
                mysqli_close($seadbcon);
 
echo "</farm>";
#echo "</stats>";
?>

Open in new window

LVL 1
jedblackAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CoyotesITCommented:
I would try moving your

$seadbcon = mysqli_connect("$hostname_seadb", "$username_seadb", "$password_seadb", "$database_seadb");

down when you are attempting to use the connection. The issue may be that the connection ID for each instance is the same, therefore only one is actually open.

When you are finished with your $nytddbon connection close it, then open the other database.

Does this have any impact?

~CoyotesIT
hieloCommented:
>>mysql_select_db($database_seadb);
did you mean mysqli_select_db?
jedblackAuthor Commented:
CoyotesIT,

I tried your suggestion.  Unfortunatly, it did'nt help.....
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

jedblackAuthor Commented:
Heilo,

I tried both mysqli_select_db and mysql_select_db...

both work...but only for the first part of the script... i still see no data comming from my Seatle connection
Roger BaklundCommented:
In line 19 you are checking for a connect error for the connect command in line 17.
You should also check for connect errors after line 12:

$nytddbcon = mysqli_connect("$hostname_nydb", "$username_nydb", "$password_nydb", "$database_nydb");
if(!$nytddbcon) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
}

In lines 34 and 92 you use mysql_selsect_db(), you should use mysqli_select_db().
As a consequence, you are changing the database on the wrong server... Use this:

mysqli_select_db($nytddbcon,$database_nydb);
mysqli_select_db($seadbcon,$database_seadb);

These functions should be called BEFORE the loop, not within.
Roger BaklundCommented:
mysql_selsect_db() changes the database on the LAST CONNECTED server...
hieloCommented:
you need to iterate over the $SERVERS again:
<?php
# header("Content-Type: text/xml");
#echo "<stats> \n";
echo "<farm>\n";
$bg_test = 2;
 
$hostname_nydb = "localhost";
$database_nydb = "nytd";
$username_nydb = "root";
$password_nydb = "";
$nytddbcon = mysqli_connect("$hostname_nydb", "$username_nydb", "$password_nydb", "$database_nydb") or die("Connect failed: ", mysqli_connect_error());
 
$hostname_seadb = "sysdb1";
$database_seadb = "nytd";
$username_seadb = "stats";
$password_seadb = "stats";
$seadbcon = mysqli_connect("$hostname_seadb", "$username_seadb", "$password_seadb", "$database_seadb") or die("Connect failed: ", mysqli_connect_error());
 
 
$SERVERS = file('lists/wwwgslb.list');
foreach($SERVERS as $SERVER)
{
	$SRV = rtrim($SERVER);
	#echo $SRV;
 
	$nytdsql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
 
	#$sql = "SELECT * FROM stats_page where server_name = 'web%t'";
	#echo $sql;
	#$sql = "SELECT * FROM host";
	mysqli_select_db($database_nydb);
	$nytdres = mysqli_query($nytddbcon, $nytdsql);
 
	if ($nytdres)
	{
		while ($newArray = mysqli_fetch_array($nytdres, MYSQLI_ASSOC))
		{
			$id  = $newArray['id'];
			$hostname = $newArray['description'];
			$load1 = $newArray['load1'];
			$cpu_idle = $newArray['cpu_idle'];
			$connections = $newArray['connections'];
			$hostname = $newArray['description'];
			$no_hits = $newArray['hits'];
			$diff_hits = $newArray['diff_hits'];
			$hitsper = $newArray['hitsper'];
			$hitspersec = sprintf("%.0f", $hitsper);
			$dl_time = $newArray['dl_time'];
			$date = $newArray['date'];
			$swap_avail = $newArray['swap_avail'];
			$swap_total = $newArray['swap_total'];
			$result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
			#$result_swap =  ( $swap_avail / $swap_total * 100);
			$real_avail = $newArray['real_avail'];
			$real_total = $newArray['real_total'];
			$result_real = sprintf("%.0f", $real_avail / $real_total * 100);
			if (($bg_test % 2) == 0)
			{
				$BGCOLOR = "FFFFFF";
			}
			else
			{
				$BGCOLOR = "cccccc";
			}
			$bg_test++;
 
			echo $display_block ="
                   <server>
                       <id>$id</id>
                       <name>$hostname</name>
                       <load>$load1</load>
                       <cpuidle>$cpu_idle</cpuidle>
                       <memfree>$result_real</memfree>
                       <swapfree>$result_swap</swapfree>
                       <numconns>$connections</numconns>
                       <hitspersec>$hitspersec</hitspersec>
                       <numhits>$no_hits</numhits>
                       <dltime>$dl_time</dltime>
                       <lastupdated>$date</lastupdated>
                   </server>";
		}
	}
	else
	{
		printf("Could not retrieve records: %s\n", mysqli_error($nytddbcon));
	}
}
 
foreach($SERVERS as $SERVER){
	$seasql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
 
##--------------------------------------------------------------------------------
## start of the seatle pull/display
##------------------------------------------------------------------------------
	mysqli_select_db($database_seadb);
	$seares = mysqli_query($seadbcon, $seasql);
 
	if ($seares)
	{
                while ($newArray1 = mysqli_fetch_array($seares, MYSQLI_ASSOC)) {
                  $id  = $newArray1['id'];
                  $hostname = $newArray1['description'];
                  $load1 = $newArray1['load1'];
                  $cpu_idle = $newArray1['cpu_idle'];
                  $connections = $newArray1['connections'];
                  $hostname = $newArray1['description'];
                  $no_hits = $newArray1['hits'];
                  $diff_hits = $newArray1['diff_hits'];
                  $hitsper = $newArray1['hitsper'];
                  $hitspersec = sprintf("%.0f", $hitsper);
                  $dl_time = $newArray1['dl_time'];
                  $date = $newArray1['date'];
                  $swap_avail = $newArray1['swap_avail'];
                  $swap_total = $newArray1['swap_total'];
                  $result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
                  #$result_swap =  ( $swap_avail / $swap_total * 100);
                  $real_avail = $newArray1['real_avail'];
                  $real_total = $newArray1['real_total'];
                  $result_real = sprintf("%.0f", $real_avail / $real_total * 100);
if (($bg_test % 2) == 0){
        $BGCOLOR = "FFFFFF";
        }
else {
        $BGCOLOR = "cccccc";
        }
 
$bg_test++;
 
echo $display_block =
"
    <server>
        <id>$id</id>
        <name>$hostname</name>
        <load>$load1</load>
        <cpuidle>$cpu_idle</cpuidle>
        <memfree>$result_real</memfree>
        <swapfree>$result_swap</swapfree>
        <numconns>$connections</numconns>
        <hitspersec>$hitspersec</hitspersec>
        <numhits>$no_hits</numhits>
        <dltime>$dl_time</dltime>
        <lastupdated>$date</lastupdated>
    </server>
 
"; 
}
       } else {
               printf("Could not retrieve records: %s\n", mysqli_error($seadbcon));
       }
}
}
       mysqli_free_result($nytdres);
                mysqli_free_result($seares);
        mysqli_close($nytddbcon);
                mysqli_close($seadbcon);
 
echo "</farm>";
#echo "</stats>";
?>
 

Open in new window

hieloCommented:
typos found on the previous post. Try this:
<?php
# header("Content-Type: text/xml");
#echo "<stats> \n";
echo "<farm>\n";
$bg_test = 2;
 
$hostname_nydb = "localhost";
$database_nydb = "nytd";
$username_nydb = "root";
$password_nydb = "";
$nytddbcon = mysqli_connect("$hostname_nydb", "$username_nydb", "$password_nydb", "$database_nydb") or die("Connect failed: ", mysqli_connect_error());
 
$hostname_seadb = "sysdb1";
$database_seadb = "nytd";
$username_seadb = "stats";
$password_seadb = "stats";
$seadbcon = mysqli_connect("$hostname_seadb", "$username_seadb", "$password_seadb", "$database_seadb") or die("Connect failed: ", mysqli_connect_error());
 
 
$SERVERS = file('lists/wwwgslb.list');
foreach($SERVERS as $SERVER)
{
	$SRV = rtrim($SERVER);
	#echo $SRV;
 
	$nytdsql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
 
	#$sql = "SELECT * FROM stats_page where server_name = 'web%t'";
	#echo $sql;
	#$sql = "SELECT * FROM host";
	mysqli_select_db($database_nydb);
	$nytdres = mysqli_query($nytddbcon, $nytdsql);
 
	if ($nytdres)
	{
		while ($newArray = mysqli_fetch_array($nytdres, MYSQLI_ASSOC))
		{
			$id  = $newArray['id'];
			$hostname = $newArray['description'];
			$load1 = $newArray['load1'];
			$cpu_idle = $newArray['cpu_idle'];
			$connections = $newArray['connections'];
			$hostname = $newArray['description'];
			$no_hits = $newArray['hits'];
			$diff_hits = $newArray['diff_hits'];
			$hitsper = $newArray['hitsper'];
			$hitspersec = sprintf("%.0f", $hitsper);
			$dl_time = $newArray['dl_time'];
			$date = $newArray['date'];
			$swap_avail = $newArray['swap_avail'];
			$swap_total = $newArray['swap_total'];
			$result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
			#$result_swap =  ( $swap_avail / $swap_total * 100);
			$real_avail = $newArray['real_avail'];
			$real_total = $newArray['real_total'];
			$result_real = sprintf("%.0f", $real_avail / $real_total * 100);
			if (($bg_test % 2) == 0)
			{
				$BGCOLOR = "FFFFFF";
			}
			else
			{
				$BGCOLOR = "cccccc";
			}
			$bg_test++;
 
			echo $display_block ="
                   <server>
                       <id>$id</id>
                       <name>$hostname</name>
                       <load>$load1</load>
                       <cpuidle>$cpu_idle</cpuidle>
                       <memfree>$result_real</memfree>
                       <swapfree>$result_swap</swapfree>
                       <numconns>$connections</numconns>
                       <hitspersec>$hitspersec</hitspersec>
                       <numhits>$no_hits</numhits>
                       <dltime>$dl_time</dltime>
                       <lastupdated>$date</lastupdated>
                   </server>";
		}
	}
	else
	{
		printf("Could not retrieve records: %s\n", mysqli_error($nytddbcon));
	}
}
 
 
##------------------------------------------------------------------------------
## start of the seatle pull/display
##------------------------------------------------------------------------------
foreach($SERVERS as $SERVER)
{
	$SRV = rtrim($SERVER);
	#echo $SRV;
 
	$seasql = "SELECT * FROM stats_page_all where server_name = '$SRV'";
 
	mysqli_select_db($database_seadb);
	$seares = mysqli_query($seadbcon, $seasql);
 
	if ($seares)
	{
		while ($newArray1 = mysqli_fetch_array($seares, MYSQLI_ASSOC))
		{
			$id  = $newArray1['id'];
			$hostname = $newArray1['description'];
			$load1 = $newArray1['load1'];
			$cpu_idle = $newArray1['cpu_idle'];
			$connections = $newArray1['connections'];
			$hostname = $newArray1['description'];
			$no_hits = $newArray1['hits'];
			$diff_hits = $newArray1['diff_hits'];
			$hitsper = $newArray1['hitsper'];
			$hitspersec = sprintf("%.0f", $hitsper);
			$dl_time = $newArray1['dl_time'];
			$date = $newArray1['date'];
			$swap_avail = $newArray1['swap_avail'];
			$swap_total = $newArray1['swap_total'];
			$result_swap =  sprintf("%.2f", $swap_avail / $swap_total * 100);
			#$result_swap =  ( $swap_avail / $swap_total * 100);
			$real_avail = $newArray1['real_avail'];
			$real_total = $newArray1['real_total'];
			$result_real = sprintf("%.0f", $real_avail / $real_total * 100);
			if (($bg_test % 2) == 0)
			{
				$BGCOLOR = "FFFFFF";
			}
			else
			{
				$BGCOLOR = "cccccc";
			}
			$bg_test++;
			echo $display_block =
			"
              <server>
                  <id>$id</id>
                  <name>$hostname</name>
                  <load>$load1</load>
                  <cpuidle>$cpu_idle</cpuidle>
                  <memfree>$result_real</memfree>
                  <swapfree>$result_swap</swapfree>
                  <numconns>$connections</numconns>
                  <hitspersec>$hitspersec</hitspersec>
                  <numhits>$no_hits</numhits>
                  <dltime>$dl_time</dltime>
                  <lastupdated>$date</lastupdated>
              </server>
			"; 
		}//end:while
	}
	else
	{
		printf("Could not retrieve records: %s\n", mysqli_error($seadbcon));
	}
}//end:foreach
 
 
mysqli_free_result($nytdres);
mysqli_free_result($seares);
mysqli_close($nytddbcon);
mysqli_close($seadbcon);
 
echo "</farm>";
#echo "</stats>";
?>
 

Open in new window

jedblackAuthor Commented:
heilo,

I tried your last post, nothing is displaying now through my browser

I get this when i run through the command line...

PHP Parse error:  parse error, unexpected ',' in /web/stats/wwwtest.php on line 11

When remove the comma, I get this

PHP Parse error:  parse error, unexpected T_STRING in /web/stats/wwwtest.php on line 11


hieloCommented:
>>or die("Connect failed: ". mysqli_connect_error());

change the comma to a period:
...or die("Connect failed: " . mysqli_connect_error());

hieloCommented:

$hostname_nydb = "localhost";
$database_nydb = "nytd";
$username_nydb = "root";
$password_nydb = "";
$nytddbcon = mysqli_connect("$hostname_nydb", "$username_nydb", "$password_nydb", "$database_nydb") or die("Connect failed: ". mysqli_connect_error());
 
$hostname_seadb = "sysdb1";
$database_seadb = "nytd";
$username_seadb = "stats";
$password_seadb = "stats";
$seadbcon = mysqli_connect("$hostname_seadb", "$username_seadb", "$password_seadb", "$database_seadb") or die("Connect failed: ". mysqli_connect_error());

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger BaklundCommented:
mysqli_select_db() needs the link as the first parameter:


mysqli_select_db($nytddbcon,$database_nydb);
mysqli_select_db($seadbcon,$database_seadb);

These functions should be called BEFORE the loop, not within.
jedblackAuthor Commented:
Hielo, thanks so much, that worked....
hieloCommented:
you are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.