Jump to content

Remote MySql


unidox

Recommended Posts

You have to check each database. If a record is found in one but the password does not match check the other and see. If the record is found and password matches no need to check the other one.

 

As far as it goes just setup a routine with what I just explained and you should be fine.

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-261631
Share on other sites

You have to check each database. If a record is found in one but the password does not match check the other and see. If the record is found and password matches no need to check the other one.

 

As far as it goes just setup a routine with what I just explained and you should be fine.

 

But how do I do that?

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-261637
Share on other sites

Learning PHP and if statements ???

 

<?php

  $conn1 = mysql_connect("1.1.1.1", "user", "pass");
  $conn2 = mysql_connect("2.2.2.2", "user", "pass");

  $query = "SELECT * FROM table_users WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1;";
  $result = mysql_query($query, $conn1);
  if (mysql_num_rows($result) < 1) {
       $result = mysql_query($query, $conn2);

        if (mysql_num_rows($result) < 1) {
               echo 'Sorry no user account exists here.';
               die();
        }else {
               $user_data = mysql_fetch_assoc($result);
               echo 'Welcome, ' . $user_data['username'] . '!'; 
        }
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-261639
Share on other sites

I tried it on my web server and it didnt work :(

 

I used:

 

  $conn1 = mysql_connect("1.1.1.1", "user", "pass");
  $conn2 = mysql_connect("2.2.2.2", "user", "pass");

  $query = "SELECT * FROM table1";

  $results_from_conn1 = mysql_query($query, $conn1);

  $results_from_conn2 = mysql_query($query, $conn2);

 

and replaced:

 

$dbinfo = array();	$dbinfo[host] = 	"localhost";	$dbinfo[user] = 	"****";	$dbinfo[pass] = 	"****";	$dbinfo[db] = 	"****";		if ($dbinfo) {			$connection = @mysql_connect ($dbinfo[host], $dbinfo[user], $dbinfo[pass]);			if ($connection) {				@mysql_select_db ($dbinfo[db]);			} else {				echo "Unable to connect to database";				exit;			}		} else {			echo "You need to setup your mysql information";

 

in http://php.privatepaste.com/f0IKClQgM6

 

What did I do wrong?

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-263886
Share on other sites

Make it so I only have the script on my server. But my clients can come and login to edit their sites. There sites will hold the sql db's.Example:

 

Person A Has Site X

Person B Has Site Z

 

Person A and B goto the same site(my site) and login.

 

Person A is able to edit Site X

Person B is able to edit Site Z

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264016
Share on other sites

frost example

<?php

 $conn1 = mysql_connect("1.1.1.1", "user", "pass");
 $conn2 = mysql_connect("2.2.2.2", "user", "pass");

 $query = "SELECT * FROM table_users WHERE username = '" . $username . "' AND password = '" . $password . "' LIMIT 1;";
 $result = mysql_query($query, $conn1);
 if (mysql_num_rows($result) < 1) {
      $result = mysql_query($query, $conn2);

       if (mysql_num_rows($result) < 1) {
              echo 'Sorry no user account exists here.';
              die();
       }else {
              $user_data = mysql_fetch_assoc($result);
              echo 'Welcome, ' . $user_data['username'] . '!'; 
       }
 }
?>

 

$conn1 = mysql_connect("1.1.1.1", "user", "pass");
 $conn2 = mysql_connect("2.2.2.2", "user", "pass");

 

frost provided u a code snippet that cheeks to see if a user exists from 2 mysql databases.

 

from frost example there are two mysql database servers with relevent ip address to the mysql databases.

 

from the example provided each ip is allowcated a mysql database meaning 2 pc setup with mysql and 2 ip going from one box to the other.

 

 

as you can see each box for both mysql databases have there own username and password.

 

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264027
Share on other sites

An example that does roughly what you want.

 

<?php

  // collect these values from a form.
  $uname = $_POST['uname'];
  $upass = $_POST['upass'];
  $host = $_POST['host'];
  $db = $_POST['db'];

  if ($conn = mysql_connect($host, $uname, $upass)) {
    if (!mysql_select_db($db)) {
      echo "Failed to select the database $db on $host";
    }
  } else {
    echo "Failed to connect to $host";
  }

?>

 

All going well, $conn would now be able to be used by your control panel to allow users to maintain there database.

Link to comment
https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264034
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.