【发布时间】:2012-12-13 08:59:41
【问题描述】:
可能重复:
How to access mysqli connection in another class on another page?
我有一个用于连接 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();
?>
提前致谢!
【问题讨论】:
-
是的,这是可能的。实例化和使用。我们在这个主题上有一些重复。
标签: php mysqli prepared-statement