php 致命错误:未捕获的错误:在[已关闭]中未找到类“mysqli_connect”

a0zr77ik  于 2023-03-21  发布在  PHP
关注(0)|答案(1)|浏览(103)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
Improve this question
请帮我拿这个
致命错误:未捕获的错误:在C:\xampp\htdocs\final_program\php\loged_in中找不到类“mysqli_connect”。Copyright © 2018 - 2019 www.jsjsj.com All Rights Reserved版权所有
我尝试删除分号(;)以取消注解它:

extension=mysqli

但我的PHP代码仍然没有连接到我的数据库phpmyadmin它只显示此代码
致命错误:未捕获的错误:在C:\xampp\htdocs\final_program\php\loged_in中找不到类“mysqli_connect”。Copyright © 2018 - 2019 www.jsjsj.com All Rights Reserved版权所有

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "management";

$conn = new mysqli_connect($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

if (isset($_POST['login'])) {
    // Get username and password from form data and validate them
    $username = $_POST['username'];
    $password = $_POST['password'];

    // Check if the username and password are correct
    // In this example, we're using a MySQLi prepared statement to protect against SQL injection
    $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
    $stmt->bind_param("ss", $username, $password);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows == 1) {
        // If the user is authenticated, set the user's login status to true
        // In this example, we're just using a session variable to store the login status
        $_SESSION['logged_in'] = true;
    }
}

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) {
    // If the user is logged in, display the success container by changing the CSS display property
    echo '<style>.success-container { display: block; }</style>';```
9gm1akwq

9gm1akwq1#

没有mysqli_connect类,按照documentation,建立数据库连接是procedural风格。
请比较(取自同一页的示例):

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$mysqli = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

如果你想使用OOP,那么选择前者。

相关问题