我真的是 PHP 和 Mysql 的初学者。我在基于CentOS(仅命令提示符)的静态 IP 192.168.1.211上创建了一个数据库,并且在此 IP 上没有像 easyPHP 这样的其他软件,我正在处理基于Windows 7的静态 IP 192.168.1.20。我还安装了easyPHP和Dreamweaver ...使用Dreamweaver制作了一个.php文件,并尝试使用192.168.1.20上的数据库..
使用下面的代码
<?php
$server2 = '192.168.1.211';
$con = mysqli_connect(server2,'root','password','vvani');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
但我收到如下所示的错误
Notice: Use of undefined constant server2 - assumed 'server2' in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP-DevServer-13.1VC9\data\localweb\test\welcome.php on line 4
Failed to connect to MySQL: php_network_getaddresses: getaddrinfo failed: No such host is known.
如何在 PHP 代码中从 192.168.1.20 访问 192.168.1.211 上的数据库?
我也努力从谷歌那里找到一个解决方案,但我没有得到一个完美的解决方案。