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
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
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
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
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
Share on other sites

I have explained what needs to be done. Your clients need to allow permissions to connect from your domain, then, you would simply have them fill in a form with there database servers public ip and there username / password combo.

 

Which part are you stuck with?

Link to comment
Share on other sites

That code provided was a simple example.

 

Do they have to input their db in order to login?

 

If you want them to be able to login to there own database, yes, of course they are going to need to supply the relevent infomation.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.