PHP and SQL or Just Database program?

Hello i am in a need for a way to easily cross-check data between more databases.

What exactly i have in mind is this.
1st Database(find table->all rows->and 1 specific column)->2nd Database(find table->find the name values of all rows of 1st Database->and check if the specific column value is bigger or equal as in the 1st Database)

My question is, can i only make this happen with PHP? It is just that i think i have stumbled upon a program that might be able to do this just by drawing boxes and then editing them. Problem is that it was long time ago.

Any answer might help, thanks.

Comments

  • i don't think there is any other way...but i think php to do this is a good choice...
  • Any manual you could recommend that could explain how to do this right on php?
  • this is how to connect to a database with php..
    http://www.w3schools.com/php/php_mysql_connect.asp
    all u have to do...is connect to the two databases... & use..'mysql_query()' to get a value..& put it in a variable... than compare between the two values..
  • i have been trying awhile and something still isnt working. Since i am a newbie in php would be glad to hear where are the problems.
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    
    
    if ($value1 == $value2)
    	{
    	echo hello;
    	}
    
    mysql_close($con);
    ?>
    
    Now i just tried to confirm that this works by echoing hello, but it somehow isnt working..
  • Amerika wrote:
    i have been trying awhile and something still isnt working. Since i am a newbie in php would be glad to hear where are the problems.
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    
    
    if ($value1 == $value2)
    	{
    	echo hello;
    	}
    
    mysql_close($con);
    ?>
    
    Now i just tried to confirm that this works by echoing hello, but it somehow isnt working..
    You should check both if $value1 and 2 are not null. If they can't get data from the database they are both null, therefore your statement says(not 100% sure about this): if(null == null) which is "true". So can check if the values are null by doing something like: if(!$value1) die(mysql_error());

    This way if anything goes wrong it'll be displayed in the browser. Also, though it's not mandatory, it's good practice to put table and column names between backticks: ` .
  • Shiru wrote:
    You should check both if $value1 and 2 are not null. If they can't get data from the database they are both null, therefore your statement says(not 100% sure about this): if(null == null) which is "true". So can check if the values are null by doing something like: if(!$value1) die(mysql_error());

    This way if anything goes wrong it'll be displayed in the browser. Also, though it's not mandatory, it's good practice to put table and column names between backticks: ` .
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    
    if(!$value1) die(mysql_error());
    
    if ($value1 == $value2)
    	{
    	echo hello;
    	}
    
    mysql_close($con);
    ?>
    
    Still an blank page..
  • Amerika wrote:
    My question is, can i only make this happen with PHP? It is just that i think i have stumbled upon a program that might be able to do this just by drawing boxes and then editing them. Problem is that it was long time ago.

    Are you thinking of phpMyAdmin?

    Screenshots: http://www.phpmyadmin.net/home_page/try.php
  • hey my friend u have a simple problem with the echo hello.... it must be like this
    echo "hello";
    
  • if u still hava a problem than you may try this :
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    $array1 = mysql_fetch_array($value1);
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    $array2 = mysql_fetch_array($value2);
    
    foreach (array_combine($array1, $array2) as $a1 => $a2)
    
    	{
    	
    		
    		if ($a1 == $a2)
    			{
    			echo "hello";
    			}
    		else echo "not the same";
    		
    	}
    
    
    
    mysql_close($con);
    ?>
    
  • FiRaS wrote:
    if u still hava a problem than you may try this :
    <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    $array1 = mysql_fetch_array($value1);
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    $array2 = mysql_fetch_array($value2);
    
    foreach (array_combine($array1, $array2) as $a1 => $a2)
    
    	{
    	
    		
    		if ($a1 == $a2)
    			{
    			echo "hello";
    			}
    		else echo "not the same";
    		
    	}
    
    
    
    mysql_close($con);
    ?>
    
    This atleast worked and showed not the same. Maybe the script was made that it checks if all the values are the same then it says hello?
    The data from my first table_1:
    user_id 	column_1
    107 	Amerika
    2664 	Elpo
    1027 	Selina*
    264 	unreal.
    652 	Wyy*
    1856 	|ProFromSky| Go0dFather
    2601 	Zaledajs
    
    The data from my second table_2:
    plrid 	column_2 	totaluses 	firstseen
    1 	eax 	4 	2010-10-02 20:40:06
    2 	RECYWYWISTA 	7 	2010-10-02 20:40:07
    3 	Dead Line_ 	6 	2010-10-02 20:40:08
    4 	herkulessssss 	4 	2010-10-02 20:42:16
    4 	DertHunDer 	52 	2010-10-02 20:43:18
    5 	(,)[-_-](,) 	16 	2010-10-02 20:45:34
    6 	Player 	3 	2010-10-02 20:47:53
    7 	[war3ft.ru]IAZOW 	2 	2010-10-02 20:52:21
    8 	Amerika 	1507 	2010-10-02 21:03:51
    8 	Equel 	1 	2010-10-02 21:13:01
    8 	command3r 	1 	2010-10-02 21:14:01
    9 	XoZz 	1 	2010-10-02 21:17:15
    10 	Player 	2 	2010-10-02 21:20:08
    11 	GodFather 	2 	2010-10-02 21:20:26
    12 	BaQ*(PeksiU)* 	2 	2010-10-02 21:21:03
    
    What i was trying to make is to make a script that checks if the column_1 values ar found in the column_2 values. If it is equal then it would show hello for each equal answer. Is the script somehow wrong?
  • i didn't understand the idea good....do you mean u want to check the id of the first table if it's found in the other table..then check between values of column one & column two..if they are the same...
    plz....tell me what the output of the script should be for these two databases...this will make it more clear.
  • At the end i should see the values from column_1 and an answer if they are in column_2. I dont want to check id's but the column_1 values.
  • <?php
    $con = mysql_connect("localhost","root","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("DB1", $con);
    
    $value1 = mysql_query("SELECT column_1 FROM table_1");
    $array1 = mysql_fetch_array($value1);
    
    mysql_select_db("DB2", $con);
    
    $value2 = mysql_query("SELECT column_2 FROM table_2");
    $array2 = mysql_fetch_array($value2);
    
    foreach ($array1 as $a1)
    
    	{
    		foreach ($array2 as $a2){
    	
    		
    		if ($a1 == $a2)
    			{
    			echo $a1."exists in both tables.";
    			}
    		
    		}
    		
    		
    	}
    
    
    
    mysql_close($con);
    ?>
    
  • Just tested your script, it didnt work, but i created 2 databases with only 1 line and one value. Then the script shows:
    Amerikaexists in both tables.Amerikaexists in both tables.Amerikaexists in both tables.Amerikaexists in both tables.
    
    4 times the same text..
    I added 2 more lines with values lol and heya, but still only shows:
    Amerikaexists in both tables.Amerikaexists in both tables.Amerikaexists in both tables.Amerikaexists in both tables.
    
    Why is that?
  • its really straaange... :S I cant do more than that sorry.. I tried to help.. :)
  • Can you test your own script in your free time? If it isnt working for you too then its wrong in the sql or code, but if its working for you then its my fault.

    Ofcourse this is if you have an free sql server and an web server. Would be glad but ofcourse i dont want to waste your time a lot. Even though thanks for the help
  • of course i have man...don't worry i'll try...& maybe these two days i'll give u an answer. :)
Sign In or Register to comment.