统一消息平台
<?php
// 定义统一消息管理平台类
class UnifiedMessagePlatform {
private $db;
public function __construct($host, $username, $password, $database) {
$this->db = new mysqli($host, $username, $password, $database);
if ($this->db->connect_error) {

die("连接失败: " . $this->db->connect_error);
}
}
public function sendMessage($recipient, $message) {
$stmt = $this->db->prepare("INSERT INTO messages (recipient, message, sent_at) VALUES (?, ?, NOW())");
$stmt->bind_param("ss", $recipient, $message);
$stmt->execute();
$stmt->close();
}
}
// 创建实例并发送消息
$ump = new UnifiedMessagePlatform('localhost', 'root', '', 'student_system');
$ump->sendMessage('student123', '您的成绩已发布,请登录查看。');
// 数据库表结构设计
// CREATE TABLE messages (
// id INT(11) AUTO_INCREMENT PRIMARY KEY,
// recipient VARCHAR(255) NOT NULL,
// message TEXT NOT NULL,
// sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
// );
?>