无法通过hostinger.com连接到mysql数据库

au9on6nz  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(397)

我正试图通过hostinger.com帐户上的phpmyadmin连接到mysql数据库,但是每次我注册到创建的表单时,我输入的数据都不会进入我的数据库(我在xampp服务器上完成了,所以我确信我没有做错任何事),而且我还更改了数据库用户名、名称、主机和密码:

<?php

$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "loginsystem";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>

<?php

$dbServername = "serverexample.hostinger.com";
$dbUsername = "u123456789_username";
$dbPassword = "password";
$dbName = "u123456789_name";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
?>

但它仍然不起作用,我还尝试搜索了一个数据库连接测试仪,它是这样的:

<?php

# Fill our vars and run on cli

# $ php -f db-connect-test.php

$dbname = 'u123456789_name';
$dbuser = 'u123456789_username';
$dbpass = 'password';
$dbhost = 'serverexample.hostinger.com';

$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");

$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);

$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}

if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
}

它告诉我:http://u920040733.hostingerapp.com/
编辑:问题是服务器名,应该是localhost xd。

ldioqlga

ldioqlga1#

可能无法从域外访问数据库
霍廷格教程
干杯,

相关问题