<?php
// 学生类定义
class Student {
public $id;
public $name;
public $department;
public function __construct($id, $name, $department) {
$this->id = $id;
$this->name = $name;
$this->department = $department;
}
}
// 工作人员类定义
class Staff {
public $id;
public $name;
public $role;
public function __construct($id, $name, $role) {
$this->id = $id;
$this->name = $name;
$this->role = $role;
}
}
// 数据库连接配置
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "university_management";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
// 示例插入学生信息
$sql = "INSERT INTO students (id, name, department)
VALUES ('1', '张三', '计算机科学')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!