unidox Posted May 25, 2007 Author Share Posted May 25, 2007 So that code, will allow anyone to login through my panel and edit a site. But how does the login know which database to look in? Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-261547 Share on other sites More sharing options...
unidox Posted May 25, 2007 Author Share Posted May 25, 2007 bump Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-261626 Share on other sites More sharing options...
per1os Posted May 25, 2007 Share Posted May 25, 2007 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 More sharing options...
unidox Posted May 25, 2007 Author Share Posted May 25, 2007 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 More sharing options...
per1os Posted May 25, 2007 Share Posted May 25, 2007 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 More sharing options...
unidox Posted May 29, 2007 Author Share Posted May 29, 2007 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 More sharing options...
unidox Posted May 29, 2007 Author Share Posted May 29, 2007 bump Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-263994 Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 What exactly are you trying to do? Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264005 Share on other sites More sharing options...
unidox Posted May 29, 2007 Author Share Posted May 29, 2007 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 More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 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 https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264020 Share on other sites More sharing options...
unidox Posted May 29, 2007 Author Share Posted May 29, 2007 I get allowing the remote connection. When I replaced the information, I just got errors. Do they have to input their db in order to login? Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264023 Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 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 https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264026 Share on other sites More sharing options...
redarrow Posted May 29, 2007 Share Posted May 29, 2007 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 More sharing options...
unidox Posted May 29, 2007 Author Share Posted May 29, 2007 I will test when I get home from school. Thanks Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264028 Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 I will test when I get home from school. Thanks Once again... these are examples. Do you have two database servers at home to test this with? Link to comment https://forums.phpfreaks.com/topic/51030-remote-mysql/page/2/#findComment-264029 Share on other sites More sharing options...
trq Posted May 29, 2007 Share Posted May 29, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.