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.
Related
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.
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.
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.
How can I connect my localhost PHP files to my remote server MYSQL database?
For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database.
How do I do that?
Thanks.
If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.
For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.
A couple of notes :
Your remote host must accept connections to MySQL (think about the firewall)
Your remote MySQL database server must accept connections from non-localhost
Sending queries, and fetching results, to/from a far away server will be a lot slower than doing so on localhost !
mysql_connect(SQL_IP, SQL_NAME, SQL_PASS);
Well when you install Wordpress set the host to be the IP of your remote server. If this isn't what you're looking for, please reword your question. If you're not using word press, check ou the PHP documentation for mysql_connect. The first parameter is the host. Enter the IP or hostname of your remote server here. And then follow that with your username and password.
mysql_connect('remote-host', 'myuser', 'mypassword');
Note: Some hosts do not allow remote connections to MySQL. Check your remote server doesn't have 3306 firewalled or only instructed MySQL to bind it to 127.0.0.1.
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)