我们提供消息推送系统招投标所需全套资料,包括消息推送系统介绍PPT、消息推送系统产品解决方案、
消息推送系统产品技术参数,以及对应的标书参考文件,详请联系客服。
// 创建数据库连接
$conn = new mysqli('localhost', 'username', 'password', 'university');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 创建消息表
$sql = "CREATE TABLE messages (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
sender VARCHAR(30) NOT NULL,
receiver VARCHAR(30) NOT NULL,
message TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table messages created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
]]>
// 发送消息函数
function sendMessage($sender, $receiver, $message) {
global $conn;
$stmt = $conn->prepare("INSERT INTO messages (sender, receiver, message) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $sender, $receiver, $message);
$stmt->execute();
$stmt->close();
}
]]>
// 查询消息函数
function getMessages($receiver) {
global $conn;
$stmt = $conn->prepare("SELECT * FROM messages WHERE receiver=?");
$stmt->bind_param("s", $receiver);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo "Message from " . $row['sender'] . ": " . $row['message'] . "
";
}
$stmt->close();
}
]]>