Fatal error: Class 'mysqli' not found in /config/mySQL_class.php 行 19 コードをテストしましたが、問題の解決策が見つからないようです。昨日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
}
?>