Jump to content

Linking 2 DBs on 2 Servers


swatisonee

Recommended Posts

Hi:

 

I have a login file where a user goes to a db based on the dbtype selected.

Now

$dbtype1 links to a db on Server 1 ( that is the server on which this script is running and

$dbtype2 links to a db on Server 2

 

I created a connection-link file connectlink.php as under but  while $dbtype1 works without a problem  , $dbtype2 gives me an error 'no access to db' and user dbun1@localhost not found on db1.db .

 

What am I missing in the connectlink.php file please ? Thanks

 

login.php

===========

<?
......
if($_POST['submit']){
$dbtype = $_POST['dbtype'];

if ($dbtype == 'type1') 
   { $section = 'type1';    
     require("../x/type1/type1.php");
     } 

if ($dbtype == 'type2') 
   { $section = 'type2';    
     require("../x/type2/connectlink.php"); //the dir 'x' is a common name on both the servers''
     } 
    
//then it processes $userfile and give this 


Click <a href="'.$section.'/'.$userFile.'?Userid='.$userid.'"> here 

?>

connectlink.php

==============

<?
//this file contains db info, log and checks if user is authorised to access the db - ist check.

error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);

$dbusername2='a';
$dbpassword2='b';
$dbname2='c';
$servername = 'ip address of server or localhost ?';
$link2=mysql_connect ("$servername","$dbusername2","$dbpassword2", true);
if(!$link2){  die("Could not connect to MySQL");}
mysql_select_db("$dbname2",$link2) or die ("could not open db".mysql_error());


$dbusername1='d';
$dbpassword1='e';
$dbname1='f';
$servername = 'localhost';
$link1=mysql_connect ("$servername","$dbusername1","$dbpassword1", true);
if(!$link1){  die("Could not connect to MySQL");}
mysql_select_db("$dbname1",$link1) or die ("could not open db".mysql_error());


$sql = "SELECT * FROM Users WHERE Userid='$userid'",$link2;

$result = mysql_query($sql);
if  ($myrow = mysql_fetch_array($result)){
$login_success = 'Yes'; 
$status = "On";
....
        
               $sql2= "insert into Log (....) values(.....)",$link2;;
$result2 = mysql_query($sql2) or die  ('no access to database: ' . mysql_error());
//        echo mysql_error();      }
}

else 
{
  $failureMessage = '<p class="data"><center><font face="Verdana" size="2" color="red">Login Failure.  You are not authorised to access this database .<br /></font></center></p>';
    print $failureMessage;
$logoutMessage = 'Click <a href="../NEWDBS/mainlogout.php"> here </a>to logout </p>';

print $logoutMessage;


     exit;
  
}		


?>

Link to comment
https://forums.phpfreaks.com/topic/218280-linking-2-dbs-on-2-servers/
Share on other sites

Archived

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

×
×
  • Create New...

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.