0

I am trying to query a database that's on a server that I have a Remote Desktop connection to. What is required to be able to query a database on this server using my php web application.

4 Answers 4

1

You need:

  1. Database server application configured to allow connections from external hosts

  2. Server-side network configuration tuned to allow connections from external hosts (firewall, NAT, ...)

  3. Database user, which is granted access to database you are going to use

  4. PHP application, which connects to your database server under appropriate user

Details depend on what database server are you using.

Sign up to request clarification or add additional context in comments.

Comments

1
$link = mysql_connect($host, $username, $password);

There is nothing secure at all by the way.

Comments

1

I use something like this, but it's far from secure. I keep it in a seperate "connection.php" that are required once by other files.

$db_host = 'INSERT IP HERE';
$db_user = 'User';
//My sql password for testing purposes
$db_pass = 'PASSWORD';
//name of the database
$db_name = 'dbname';

//connection
$conn = new mysqli($db_host, $db_user, $db_pass ,$db_name);

if (mysqli_connect_errno()) 
{
    printf("Error connecting to DB, Errorcode: %s\n", mysqli_connect_error());
    exit;
}

Comments

1

use answer by Merch member - the php code above . You need to grant privileges and to create user on server you are retrieving the database data from.

Connect to mysql : in shell type (if you are root type root or whatever username): mysql -u root -p

enter password,

when you are logged in :

create user someusername@your-client-ip identified by 'password';
grant all privileges on *.* to someusername@your-client-ip with grant option;

now you can use php code above to connect to remote server database (ip you just used to create mysql user your-client-ip)

When you are creating php variable for mysql connect - host use mysql port in the variable if just ip not connects your-client-ip:3306

good luck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.