0

Hi I am making a login/register database. I am not hosting the database on the same server so how do I make it point to my separate domain? Also if you can tell me what the root is pointing to... Thx

Here are my files:

db.php

<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('register');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>

Links (my scripts and original scripts): https://docs.google.com/document/d/1u60X_mKd9z548qrh_VjdyTx3hziiZiYPLUa_rJX11mQ/edit?usp=sharing

brendan
  • 11
  • 5
  • 1
    change `localhost` to the server's domain or IP. You should look into using `mysqli` or `pdo` if just starting out. – chris85 Apr 22 '16 at 01:16
  • Simply amend the mysql_connect parameters to match your database server's host name, username and password. IP address should work fine, but also machine name or DNS entry, depending on your network setup. – ManoDestra Apr 22 '16 at 03:14

2 Answers2

1

For starters, DON'T USE mysql_connect()! Use either mysqli or PDO. Second, don't have your application log in to MySQL as root; create an application-specific unprivileged user (with a password!) for this purpose.

You'll need to create your unprivileged user with connect privilege from the web server's IP or DNS address, and instead of connecting to localhost your PHP will need to connect to the DB server's IP or DNS address, like so:

$dsn = "mysql:host=mysqlserver.mynetwork.com;dbname=register";
try
{
    $conn = new PDO($dsn, $appuser, $apppasswd);
}
catch (PDOException $e)
{
    echo 'Connection failed: ' . $e->getMessage();
}
Community
  • 1
  • 1
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
0

You could try the following example

$server = "192.168.1.1"; //server name or IP Address 
$username = "root"; //database username
$password = "password"; //database password
$database = "mydatabase";   //database to connect to

$connection = mysqli_connect( $server, $username, $password, $database);

if (!$connection){
   die("Database Connection Failed" . mysqli_error());
}

else{

//sql statement

}

mysqli_close($connection);

Thanks

user2168287
  • 101
  • 1
  • 10