[英]Cannot connect to MySQL on VPS Server
I want to connect to a VPS server with the following code. 我想使用以下代码连接到VPS服务器。 What is wrong with it?
怎么了
<?php
$con = mysqli_connect("A.B.C.D", "user", "pass", "db1");
if (!$con) {
die("Could not connect: ".mysqli_errno());
}
$sql = "SELECT * FROM table1";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
extract($row);
echo $name;
?>
The above code gives the error : Could not connect: 上面的代码给出了错误:无法连接:
However, when I use "localhost" and run this script on a copy of that database and table that I have in my laptop, it runs smoothly and echoes the name from the first record in the table. 但是,当我使用“ localhost”并在我的笔记本电脑中拥有的该数据库和表的副本上运行此脚本时,该脚本将平稳运行并回显表中第一条记录的名称。
Why am I not being able to connect to my VPS? 为什么我无法连接到VPS?
Make sure MySQL has enabled outside access, you probably don't have access from remote machines to the VPS. 确保MySQL启用了外部访问,您可能没有从远程计算机到VPS的访问权限。
UPDATE: Do you have access to phpmyadmin or a tool like that? 更新:您可以访问phpmyadmin或类似的工具吗?
Check the following; 检查以下内容;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.