<?php
// 高校资产管理系统的核心功能之一是资产信息管理
class Asset {
private $id;
private $name;
private $type;
private $location;
public function __construct($id, $name, $type, $location) {
$this->id = $id;
$this->name = $name;
$this->type = $type;
$this->location = $location;
}
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
public function getType() {
return $this->type;
}
public function getLocation() {
return $this->location;
}
}
// 数据库连接
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "asset_management";
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 创建表
$sql = "CREATE TABLE IF NOT EXISTS assets (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
type VARCHAR(30),
location VARCHAR(50)
)";
if ($conn->query($sql) === TRUE) {
echo "Table assets created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
// 插入数据
$stmt = $conn->prepare("INSERT INTO assets (name, type, location) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $name, $type, $location);
// 设置参数并执行
$name = "投影仪";
$type = "教学设备";
$location = "第一实训室";
$stmt->execute();
echo "New record created successfully";
$stmt->close();
$conn->close();
?>