Connecting to remote Mysql databases from Php scripts - php

I have two websites (managed separately with Cpanel). I want to use a database on one host from another.
Domains and their mysql ports are: abc.com:2082 and xyz.com:2082.
I would like to use the database on abc.com from a Php script running on xyz.com. However when I try to connect to the database, the connection is showing an error: "Error".

Well, You can do it in two ways first connecting database using database credential. in that case, you need to enable mysql remote permission . if provide % then anyone from any ip address can connect with your database.
Secondly, You can use restful api to exchange data in between. to know more about restful api search in the stackoverflow.

Related

Using PHP/IIS to connect to a different server

I am trying to connect to a different computer so I can connect to a specific instance on mssql_server. I have PHP configured on IIS, but I am not sure how to connect to the separate computer.
You're looking for something to connect with. A quick search sent me to php.net's sqlsrv-connect. The bit in there about the connection string is what you'd need to define, to connect to the appropriate machine / database using the appropriate user / password.

retrieve data from mysql database using php from a different computer

I am a newbie on PHP . Can someone tell me how to connect and retrieve data from mysql database server using PHP from a different computer.
First of all, the MySQL server must accept remote connections.
Also MySQL's user that you use, must be allowed to log from PHP computer's IP.
Then you can simply connect from your PHP server changing configuration of connection by setting host parameter to MySQL server's IP instead of localhost.
Google for mysql remote connection in order to find information about how to configure it to accept remote connections.
Localhost in name suggest locally , you cannot access mysql database from another computer .
Copy the file and install , only then it will work.

include mysql connection remotely php

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.

Connect MySQL database to several domains

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.

connecting external mysql database with php

Is that possible to connect mysql database between servers. I mean, lets say i have 2 accounts on 2 different hosting service, one of them has database, and i want to connect it from other one with php.
When i try it, i get "Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query..."
my database is located on godaddy and i set it external access enabled.
Edit:
I see it is possible but my host only allows connection via software;
"To use Direct Database Access to connect remotely to your shared hosting database, you need to download software that lets you connect to the database and manage it."
It's very possible.
Make sure the host that has your database allows for external connections and allows that username/password combination to access the database (Usually something set via mySQL's GRANT option)

Categories