可以使用php创建从localhost到另一台服务器的mysql连接,如果有可能,怎么做?谢谢!
答案 0 :(得分:1)
$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();
}
答案 1 :(得分:0)
是的,这是可能的。您必须拥有要连接的域的用户名和密码。
mysqli_connect("www.domain.com","username","password","database_name")or die("Error " . mysqli_error());
答案 2 :(得分:0)
是的,只需传递有关您服务器的以下详细信息:
<?php
$servername = "your-server-name-or-ip";
$username = "your-server-username";
$password = "your-server-password";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
答案 3 :(得分:0)
$url = 'mysql:host=xxx.xxx.xxx.xxx;dbname=xxxxxx'
$username = xxx;
$password = xxx;
$db = new PDO($url, $username, $password);
$query = $db->query('select * from some_table');
$query->execute();
$res = $query->fetchAll(PDO::FETCH_ASSOC);