数据库连接
$db_user = 'root';
$db_pass='';
$db = new PDO('mysql:host=localhost;dbname=resource_management', $db_user, $db_pass);
这里是它创建的 User 类
class User{
protected $username;
protected $pass;
public function __construct($username, $password){
$this->username = $username;
$this->password = $password;
}
public function test(){
$sql = "select * from user";
$data = $db->query($sql);
while ($row = $data->fetch(PDO::FETCH_OBJ)){
var_dump($row);
echo $row->username;
}
}
}
在这里我尝试测试 User 类
$user = new User('admin', 'test');
$user->test();