0

我正在尝试使用以下文件从 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。我不知道为什么在连接尝试后我没有收到任何消息。我应该检查服务器上的防火墙配置,我该如何检查?

谢谢!

4

2 回答 2

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);
?>

可能会抑制您的错误。所以它没有显示错误。试试看。它现在会给出错误。这将有助于找出真正的问题。:)

于 2013-08-24T16:06:43.107 回答
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);
?>

尝试这个 :)

于 2013-08-24T16:01:11.870 回答