php – 无法找到数据库

前端之家收集整理的这篇文章主要介绍了php – 无法找到数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个PHP文件,它在我的服务器上.我从chrome打开PHP文件后,显示“无法找到数据库”.
<?PHP

    $dbhost = "fdb7.biz.nf";
    $database = "2065616_knurum";
    $username = "2065616_knurum";
    $dbpass = "XXXXXXXXX";

    MysqLi_connect($dbhost,$username,$dbpass,$database);

    @MysqL_select_db($database) or die("Unable to find database");

    $name = isset($_GET["name"]) ? $_GET["name"] : '';

    $message = isset($_GET["message"]) ? $_GET["message"] : '';


    $query = "INSERT INTO test VALUES ('','$name','$message')";

    MysqL_query($query) or die (MysqL_error("error"));

    MysqL_close();

    echo"hello";
    ?>

在几位帮助者评论之后,这是正确的解决方案,并且它有效.感谢所有回复的帮助者.

$dbhost = "fdb7.biz.nf";
$database = "2065616_knurum";
$username = "2065616_knurum";
$dbpass = "XXXXXXXX";

$link = MysqLi_connect($dbhost,$database);

if (!$link) {
    echo "Error: Unable to connect to MysqL." . PHP_EOL;
    echo "Debugging errno: " . MysqLi_connect_errno() . PHP_EOL;
    echo "Debugging error: " . MysqLi_connect_error() . PHP_EOL;
    exit;
}


$name = isset($_GET["name"]) ? $_GET["name"] : '';

$message = isset($_GET["message"]) ? $_GET["message"] : '';

$query = "INSERT INTO test VALUES ('','$message')";

MysqLi_query($link,$query) or die (MysqLi_error("error"));


echo "Success: A proper connection to MysqL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . MysqLi_get_host_info($link) . PHP_EOL;
MysqLi_close($link);
?>
http://php.net/manual/en/function.mysqli-connect.php开始尝试这个参考
<?PHP

$dbhost = "fdb7.biz.nf";
$database = "2065616_knurum";
$username = "2065616_knurum";
$dbpass = "XXXXXXXXX";

$link = MysqLi_connect($dbhost,$database);

if (!$link) {
    echo "Error: Unable to connect to MysqL." . PHP_EOL;
    echo "Debugging errno: " . MysqLi_connect_errno() . PHP_EOL;
    echo "Debugging error: " . MysqLi_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MysqL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . MysqLi_get_host_info($link) . PHP_EOL;

MysqLi_close($link);
原文链接:https://www.f2er.com/php/137782.html

猜你在找的PHP相关文章