is it possible to connect to another server's database with php?
Like I have Website A thats got Database A and on this website I want to load something from a Database B of Website B. Of course I got the connection data!
its simple all thise above techniques are quite complicated
suppose you have database on server B and website on server A(say it has IP 192.234.12.1)
on cpanel whitelist the IP of server B
and create a new user having sufficient privileges in database (say this user is test)
then create this user as test#192.234.12.1
Gotten from how to connect to database on another server
Related
I know how to connect to a MySQL DB on a remote server. What I want to do is, connect to the remote mysql server on the clients site without them being able to see my connection credentials by simply downloading the sqlconnect.php file.
the reason for this is because I have built multiple sites that are almost identical. they are essentially re-seller sites. I built it in a way that one database handles all the sites and simple "site ID's" passed on by each site determine the content delivered.
I need to connect to Mysql remotely but dont want to leave the connection file on each persons server. I'm not so much interested in protecting the rest of the code, just the mysql connection credentials itself.
I have set up a website with basic HTML/CSS files and would like to take that one step further and implement a database with some PHP to perform simple queries and whatnot.
My problem arose when I noticed while setting up the database and creating the PHP files that connect to the database (on my local machine), I used 'localhost' as an argument for mysql_connect. When I then went to drag and drop my newly created HTML/PHP files along with my database into FileZilla to upload the pages onto my remote server, there was a problem connecting to the database. I have a feeling that it is unhappy with the whole 'localhost' notion - yet I don't know what to change it to.
Currently, I am using this line of PHP code to connect to my remote database (which is all located in FileZilla-land).
$link = mysql_connect('localhost','Tommy','pass')
Also, as another quick question: does my remote server have its own phpMyAdmin page? And if so... how would one go about finding it? =D
I appreciate anyone who is able to assist me in my endeavors.
Thank you!!
Log on to your database server, check the details and obtain the correct server information such as server, username and password.
Once you change the server details you shoudl be ready to rock n roll. Edit post with the host name/server name and we may be able to find it for you.
You'll have a phpMyAdmin page where you're hosting the site. Check the membership area or cPanel.
You are right in that 'localhost' in mysql_connect needs to be different. 'localhost' is a textual representation of a loopback address AFAIK - it connects to the computer it is hosted on. As you have uploaded it to your server (a different computer) it is now trying to connect to a mysql server on the server host, instead of your home computer (which holds all the data).
To make this work you'd need to get your database onto the server you are now working from, OR depending on your home setup, point it to your local database.
Whether your host has MySQL/PHPMyAdmin available to you is another matter altogether. If they have MySQL it is probable but not definite that they have a phpmyadmin interface.
Contacting the server host will yield more information. If they have MySQL, it is probably as simple as getting the required details from them, and 'backing up' your SQL on your local server and uploading it to the new server (easily done with PHPMyAdmin)
TL;DR: The database you are trying to connect to doesn't exist on the server you're connecting from.
I have two websites with different domains and I have to share data between the two, such as user registered on first website will be login on the second website too.
Is it possible to connect the second website to the first website's MySQL database? I.e. I have two websites www.example1.com and www.example2.com. Is it possible for example2.com to connect to database of example1.com?
I use the following PHP code which works fine for example1.com but not on example2.com:
$conn =mysql_connect("HOST","USERNAME","PASS") or die("cannot connect with db").mysql_error();
$dbname=mysql_select_db("DATABASE_NAME") or die("Error selecting db").mysql_error();
On example2.com, the connection fails with error message
cannot connect with db....
Could you please explain me what is the configuration required for such type of connection and what are the things which may stop this connection?
if the 2 domains are hosted in the same server then no problem at it all you may connect with the database with as much scripts as you want .
if they are in different servers from your database server you can do this but you have allow remote connection for each script IP
It depends on where you host your database and your website. Some webhostings allow only local database connection. So make sure that either both websites are on the same server or that your settings allow you to connect from your PHP code to the remote database and the database allows remote connection.
If you have command-line access to your webserver, check that you can connect using mysql command - see this answer.
I have never needed to do this before, but I am developing an application which will be installed to a users website - but it will need to query data held in a database stored on the application's server.
Server A (client - domian: www.example.com)
Server B (application).
There will be a form on Server A (a Search form) which POSTS search data to the Server B (application) along with some information about Server A (domain, IP).
Server B handler will:-
1.) Check if Server A is an actual client (i.e. is domain (www.example.com) in the allowed domains list and does the request come from the IP of Server A.
2.) If 1.) is TRUE, it will process the request, and return a response being the results of the query.
I can't seem to find anything on Google or this site where someone wants to do this? I could be searching for the wrong thing though.
Also, would there be any limits on the size of the array that is returned back to Server A??
I do not want to grant DB access to the user - unless this is the only solution (i.e. create a new mysql DB user with READ only capability upon activation of the application).??
Any help much appreciated
IF you're posting data to server b (the db host) then the query will be run locally on that server.
What you need is some script that can handle your post OR if you want to connect to the db from server A and also handle the post i server A then you have to give that server the right to connect to the db-server.
So then thing you need to do is to write a script on the server B that will handle the post.
My guess is that you're better of giving server A (proper)access rights to the db on server B.
So here is the situation.
I have a database on a remote server that gives out quizzes and scores for individual students...
I also have a local database which contains the students names and their respective groups.
What I want to do is to display the list of students per group then show the results of their scores from the remote database.. Is this possible??
Im currently running the script from my local computer using XAMMP like so
mysql_connect("REMOTE SERVER ADDRESS","USERNAME", "PASSWORD") or die("Could not connect to MySQL server!");
But all I get is Could not connect to MySql Server..
GRANT ALL ON database.* TO user#ipaddress IDENTIFIED BY 'password';
You should force a reload of the grant tables using:
FLUSH PRIVILEGES;
https://documentation.cpanel.net/display/ALD/Remote+MySQL# I found useful this one myselt. When you haven't define access permissions to remote db using it's cpanel, then you cannot connect with it via the localhost from your PC.
You will find something like 'Add Access Host' in your hosting server cpanel and there you can add which IPs are you going to use to access from outside. There I used as "%.%.%.%" and that means I allowed every v4 IPs to access my database. Instead of "%.%.%.%" you can put your PC's IP(for example 51.254.230.178). As PC's IP gets changed frequently, then I used this because I cannot change it manually all the time by checking my IP every time I connected to the Internet.