-1

我收到致命错误:第 19 行的 /config/mySQL_class.php 中找不到类 'mysqli' 我已经测试了我的代码,但似乎找不到解决问题的方法,我只是一个开始昨天尝试 OOP。有任何想法吗?

<?php


class Database
{



    public $data;

    public $mysqli;

    public function __construct($host, $username, $password, $database){

        $this->mysqli = new mysqli($host, $username, $password, $database);

        if(mysqli_connect_errno()){

            echo "Error: Could not connect to database.";

        exit;

        }
    }



    public function __destruct(){

        $this->mysqli->close();

    }


    public function read(){

    $sql = "SELECT * FROM `user` ";
    $result = $this->mysqli->query($query);
    $num_result = $result->num_rows;

    if($num_result>0)
    {

        while($rows=$result->fetch_assoc()){

            $this->data[]=$rows;

                }
            } else {

                return $this->data;

        }
    }




}

?>

用法

include('config/mySQL_class.php');

$obj=new Crud("localhost","root","","crud");
$obj->read();

    <table width="500" border="1" cellpadding="5">
      <tr>
        <th width="16" scope="row">id</th>
        <td width="95">name</td>
        <td width="140">email</td>
        <td width="104">address</td>
         <td width="71">Mobile</td>
        <td>action</td>
      </tr>

        <?php
        foreach($obj->data as $val){
            extract($val);

            ?>
            <tr>
            <td scope="row"><?php echo $id; ?></td>
            <td><?php echo $name; ?></td>
            <td><?php echo $email; ?></td>
            <td><?php echo $address; ?></td>
            <td><?php echo $mob; ?></td>
             <td><a href="edit.php?id=<?php echo $id; ?>">edit</a>|<a href="delete.php?id=<?php echo $id; ?>">Delete</a></td>
          </tr>
            <?php
        }

        ?>
4

1 回答 1

-1

当您的服务器上未安装 MySQLi 扩展时,这是一个常见错误。

要检查 MySQLi 扩展是否可用,请尝试以下操作:

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'MySQLi extension is missing!';
} else {
    echo 'MySQLi extension is installed!';
}

要安装 MySQLi 扩展,请按照此说明进行操作。

您也可能安装了 MySQLi 扩展,但在 php.ini 文件中进行了注释。打开 php.ini 并检查 extension=php_mysqli.so 是否没有被注释。如果是这样,请取消注释并重新启动 apache 服务器。

于 2013-07-02T09:30:02.053 回答