简体   繁体   English

我怎样才能创建一个数据库每年和 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?

It turns out that I need to create databases every year incrementally and automatically with their corresponding fields and tables, since, I need each database to be able to store information regarding the type of year, for example: db2021, db2022,db2023 so successively, and that the records that were made in the year 2021 are from the year 2021, records I mean the records of the database table, the typical record, and that for example with a select, you can select the year you want and the records of that year are displayed, and clearly being a new database the ids of each table start again in 1 since there are no records.事实证明,我需要每年自动增量地创建数据库,并使用相应的字段和表,因为,我需要每个数据库能够存储有关年份类型的信息,例如:db2021、db2022、db2023 如此依次,并且 2021 年制作的记录是从 2021 年开始的,记录我的意思是数据库表的记录,典型的记录,例如 select,你可以 select 你想要的年份和记录显示那一年,并且显然是一个新数据库,每个表的 id 再次从 1 开始,因为没有记录。

Example of what I have tried:我尝试过的例子:

<?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>

You have many ways to do differently:你有很多不同的方法:

  • Having a timestamp column and in query filtering whith WHERE YEAR(date) = '2022'具有时间戳列并在 WHERE YEAR(date) = '2022' 的查询过滤中
  • Having a column "Year" that you fill with YEAR(NOW())有一个用 YEAR(NOW()) 填充的“Year”列
  • And many other ways...还有很多其他方式...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM