如何创建关联的mysql表-平时看的都是单表操作的书视频什么的
PHP一直学得没进展,最近看了几个开源的东西,才又有动力学了。
一直看的书啊,视频啊都是对单个表的操作。
现在要实现一个功能,就是记录某些开源CMS的数据表的字段名称和表。
比如我要记录ecshop所有的表,并且把每个表的字段名称和类型还有注释都记录下来写到数据库里面保存起来
类似这样的,那么这样的数据库我是这样来设计的,两个表。
第一个表 one (记录表的信息,tabid关联第二个表的tid)
auid int(3) 自增,主键
tabname varchar(30) 表的名称
tabnote varchar(表的注释)
tabid int(3) 关联two表里面的 tid
addtime int(10) 添加表的时间戳
第二个表 two(记录表的字段信息)
auid int(3) 自增,主键
tname varchar (30) 字段名称
ttype varchar(20) 字段类型
tnote varchar(100) 字段的说明,注释
tid int(3) 关联第一个表 one 的tabid
==========================================
这样的话怎么样来建立数据库的时候自动关联呢,我就是不知道怎么来实现,比如现在我插入一条数据
表名称 : article_cat
表注释 : 文章分类信息
表添加时间: 1395052170
字段: type
字段类型: time
字段说明: 这是时间戳
-----------------------
那么这样的话我表单通过POST接受信息以后怎么样插入数据库呢
insert into ......
还有我上面的表的设计有问题吗,是否表与表相关的字段必须为主键之类的呢。
回复讨论(解决方案)
第一个表里 auid和tabid是重复的,使用一个就行了。
没有自动关联这一说,你要在关联字段里写上数据。
第一个表里 auid和tabid是重复的,使用一个就行了。
没有自动关联这一说,你要在关联字段里写上数据。
你的意思就是写入one表的tabid在写入的同时要自动插入到two表的tid是这样吗
那这样的话是不是就需要用到mysql的触发器
那sql的话就需要写两条了,一条是插入one表,一条是插入到two表,可以这样理解吗
建议你先去学学数据库的范式之类的基础知识。
第一个表里 auid和tabid是重复的,使用一个就行了。
没有自动关联这一说,你要在关联字段里写上数据。
你的意思就是写入one表的tabid在写入的同时要自动插入到two表的tid是这样吗
那这样的话是不是就需要用到mysql的触发器
没你想的那么复杂,保存一个列的值后,把这个列的值赋值给另一个表的对应的列就行了。。。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
