It's possible to create a mysql connection from localhost to another server using php, if it's possible, how? Thanks!
4
-
Change the connection settings, user/password/server. EX: $dbh = new PDO('mysql:host=the_server_address;dbname=test', $user, $pass);ka_lin– ka_lin2015-01-22 13:01:38 +00:00Commented Jan 22, 2015 at 13:01
-
possible duplicate of Connecting to remote MySQL server using PHPPlamen Nikolov– Plamen Nikolov2015-01-22 13:02:31 +00:00Commented Jan 22, 2015 at 13:02
-
One important thing is that your remote server should allow remote connections. stackoverflow.com/a/14779244/1501051عثمان غني– عثمان غني2015-01-22 13:15:34 +00:00Commented Jan 22, 2015 at 13:15
-
it is simple, i just want to create a connection from my localhost pc to my domaint something.something, to read the mysql db from domain, and administation from localhost, to don't connect to my server and disconect, and to this foreverEugen Paici– Eugen Paici2015-01-22 14:09:40 +00:00Commented Jan 22, 2015 at 14:09
Add a comment
|
4 Answers
$host_name = "www.yourdomain.com";
$database = "pdo"; // Change your database name
$username = "root"; // Your database user id
$password = "test"; // Your password
try {
$dbo = new PDO('mysql:host='.$host_name.';dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Comments
Yes it is possible.You must have the username and password of that domain in which you want to connect.
mysqli_connect("www.domain.com","username","password","database_name")or die("Error " . mysqli_error());
5 Comments
Rahul
please mark it useful if it works for you
عثمان غني
@UnicoRahul username password is needed for the database not for domain (host)
Rahul
@عثمان غني The question is about mysql connection and mysql connection means he wants to connect with database
عثمان غني
"You must have the username and password of that domain..." so I am saying
Rahul
عثمان غني that is obvious