我如何每年创建一个数据库,select 我想要的年份 select 并显示那一年的记录?
How can I create a database each year and select the year I want for a select and display the records for that year?
事实证明,我需要每年使用相应的字段和 table 自动增量地创建数据库,因为,我需要每个数据库都能够存储有关年份类型的信息,因为例子:db2021,db2022,db2023 依次类推,2021年的记录是2021年的记录,我指的是数据库table的记录,典型的记录,比如with a select,你可以 select 显示你想要的年份和那一年的记录,并且显然是一个新数据库每个 table 的id从1重新开始,因为没有记录。
我尝试过的示例:
<?php
$db = new Mysqli('localhost', 'user', 'password', 'database', 3306); //make connection
$db->query('CREATE DATABASE `db' . date('Y') . '`'); // create database
$db->select_db('db' . date('Y')); // select newly selected database
$db->query(file_get_contents('cambio.sql')); // import the sql file into it
select name="dbName">
<?php
for ($year = 2022; $year < date('Y') + 1; $year++) {
echo '<option value="db' . $year . '">' . $year . '</option>';
}
?>
</option>
你有很多不同的方法:
- 有一个时间戳列并且在 WHERE 查询过滤中
年(日期)= '2022'
- 有一列“年份”供您填写
年(现在())
- 还有许多其他方式...
事实证明,我需要每年使用相应的字段和 table 自动增量地创建数据库,因为,我需要每个数据库都能够存储有关年份类型的信息,因为例子:db2021,db2022,db2023 依次类推,2021年的记录是2021年的记录,我指的是数据库table的记录,典型的记录,比如with a select,你可以 select 显示你想要的年份和那一年的记录,并且显然是一个新数据库每个 table 的id从1重新开始,因为没有记录。
我尝试过的示例:
<?php
$db = new Mysqli('localhost', 'user', 'password', 'database', 3306); //make connection
$db->query('CREATE DATABASE `db' . date('Y') . '`'); // create database
$db->select_db('db' . date('Y')); // select newly selected database
$db->query(file_get_contents('cambio.sql')); // import the sql file into it
select name="dbName">
<?php
for ($year = 2022; $year < date('Y') + 1; $year++) {
echo '<option value="db' . $year . '">' . $year . '</option>';
}
?>
</option>
你有很多不同的方法:
- 有一个时间戳列并且在 WHERE 查询过滤中 年(日期)= '2022'
- 有一列“年份”供您填写 年(现在())
- 还有许多其他方式...