IGGt Posted October 29, 2010 Share Posted October 29, 2010 I'm sure there must be a way to do whatI am after, as it seems like such an obvious thing to do, but I can't figure it out. 1. I have an array which contains a list of database's and their connections $slaveRes_array[0] = array('server' => 'localhost:3306', 'user' => $u, 'password' => $p, 'database' => 'MySQL01_5083', 'sendmail' => '0', 'repeat' => '0', 'dbID' => '1' ); and so on 10 times I then have a list of MySQL Queries: (at the moment there is only one, but there will be more later on). $query_array[] = array( 'query1' => "SHOW SLAVE STATUS"); The idea is that I take the first database from $slaveRes_array, connect to it, and run each query from the $query_array in turn against that database, and ultimately pass that resultset into an array that I can refer back to later on. Within $slaveRes_array I have a DB name (e.g. MySQL01_5083), I want this to be the first entry in my resultset array, so I can reference this. However, not all database's will return a result. So what I want to end up with is something like: [0] => Array ( [name] => MySQL02_5083 ) ( [slave_IO_State] => Waiting for master to send event)... (in this case the first server (MySQL01) didn't return a result, so the first item in the array is MySQL02. I have found lots of ways to achieve bits of this, but none that work together. I can get a list of database names that returned a result, but can't get the data to return to the array (or any array). I can get the data into an array, but not the database names. Surely this must be something straight forward that people do all the time, right? Link to comment https://forums.phpfreaks.com/topic/217204-problem-with-an-array/ Share on other sites More sharing options...
IGGt Posted October 29, 2010 Author Share Posted October 29, 2010 What I have so far is: //make the relevant connection for($a = 0; $a <sizeof($slaveRes_array); $a++) { $con = mysql_connect($slaveRes_array[$a]['server'], $slaveRes_array[$a]['user'], $slaveRes_array[$a]['password']); mysql_select_db($dbs, $con); for($b = 0; $b <sizeof($query_array); $b++) { $slaveState = mysql_query($query_array[$b]['query1'], $con); and then two options: while(($slave_array2[] = mysql_fetch_assoc($slaveState)) || array_pop($slave_array2)); and: while($row = mysql_fetch_assoc($slaveState)) { if (($row['Slave_IO_Running'] == "No") || ($row['Slave_IO_Running'] == "Yes")) { //it should always report Yes / No / or nothing. Nothing means there is no resultset, and so this database should be ignored. $slave_array[]['name'] = $slaveRes_array[$a]['database'];} else { print "nothing";}; } Both of these work individually, but they don't work together. Whichever one I put on top runs, and the second one basically gets ignored. Link to comment https://forums.phpfreaks.com/topic/217204-problem-with-an-array/#findComment-1128013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.