简体   繁体   English

无法从本地主机连接到数据库

[英]Can't connect to the database out of the local host

I've been trying to connect to database using this .php code: My number port is 2086. The following code woks using the localhost bu not when I tried to run out of the localhost (on the live site). 我一直在尝试使用此.php代码连接数据库:我的电话号码端口是2086。当我尝试用尽本地主机(在实时站点上)时,以下代码使用localhost bu起作用。 There is only write "error" that strange that mysqli_connect_error() function doesn't return anything. 只有写“错误”,奇怪的是mysqli_connect_error()函数没有返回任何东西。 Can I find a solution ? 我可以找到解决方案吗?

<?php

  if ($enlace = mysqli_connect("ip+port", "username", "password", "databases"))
        echo 'connect to the databases';
  else
    {
      printf("error", mysqli_connect_error());
      exit();
    }
?>

This: 这个:

$enlace = mysqli_connect("ip+port", etc...
                            ^^^^^

is incorrect. 是不正确的。 port is specified as argument #5: 端口被指定为参数#5:

$enlace = mysqli_connect($hostname, $username, $password, $dbname, $port)
                                                                   ^^^^^

It finally work !! 终于可以了! I changed the domain name of the site and it's works. 我更改了站点的域名,并且可以正常工作。 I think the problem is due to the old domain name. 我认为问题出在旧域名。 I'm sent them a mail for try to find a solution. 我已向他们发送了一封邮件,以寻求解决方案。

thank you for all of you help 谢谢大家的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM