我有一个用于连接到 MYSQLi 数据库的 PHP 类,我想在另一个类中使用这个类来创建准备好的语句并显示来自数据库的一些信息。
这可能吗?
<?php
class database {
public $host = "localhost";
public $user = "root";
public $password = "root";
public $name = "store";
public function connect() {
$connect = new mysqli($this->host, $this->user, $this->password, $this->name);
if($connect->connect_errno > 0){
die('Unable to connect to database [' . $connect->connect_error . ']');
}
}
}
class products {
// In here I want to use a MYSQLi prepared statment to show some information
// from the database details in the class above
}
$database = new database();
$database->connect();
?>
提前致谢!