我正在尝试使用以下文件从php文件连接到linux上运行的服务器:
<?php
$db_host = "127.0.0.1";
$db_user = "userk";
$db_pss = "pass";
$tag = $_POST['tag'];
echo $tag . " Trying to connect with credentials: "
. $db_host."\n". $db_user . " " .$db_pss;
$link = mysql_connect($db_host, $db_user,$db_pss);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
输出页面是:
注册尝试连接凭据:127.0.0.1 userk pass
我已经检查过以前的问题,寻找有用的信息。但它仍然无效。
我可以使用putty从终端使用此用户连接到mysql。我不知道为什么连接尝试后我没有收到任何消息。我应该检查服务器上的防火墙配置,我该如何检查?
谢谢!
答案 0 :(得分:1)
我们知道mysql_ *现在已经折旧了,所以最好使用MYSQLI _ *:
<?php
error_reporting(E_ALL | E_NOTICE | E_STRICT );
$db_host = "localhost";
$db_user = "userk";
$db_pss = "pass";
$database="abc";
$tag = $_POST['tag'];
echo $tag . " Trying to connect with credentials: " . $db_host."\n". $db_user . " " .$db_pss" " .$database;
$link = mysqli_connect($db_host, $db_user,$db_pss,$database);
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
echo 'Connected successfully';
mysqli_close($link);
?>
可能是您的错误被抑制的情况。所以它没有显示错误。试试看。它现在会给出错误。这将有助于找出真正的问题。:)
答案 1 :(得分:0)
<?php
$db_host = "localhost";
$db_user = "userk";
$db_pss = "pass";
$tag = $_POST['tag'];
echo $tag . " Trying to connect with credentials: " . $db_host."\n". $db_user . " " .$db_pss;
$link = mysql_connect($db_host, $db_user,$db_pss);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
试试这个:)