在 PHP 中检索表的关系

发布于 2024-10-31 00:03:08 字数 282 浏览 4 评论 0原文

一段时间以来,我一直在考虑编写一个后端管理生成器。但经过一番搜索后,我仍然找不到检索表关系的解决方案。

如果可能的话,我将如何检索 PHP 中表所具有的任何关系?

更新

我想要实现的是构建一个指向数据库的脚本。然后,该脚本列出数据库中的所有表,并允许您创建/编辑/删除这些表中的记录。但我希望能够找到关系并向用户展示一个包含他们可以选择的所有值的下拉框。例如,如果列“user”链接到表“users”上的列“id”。然后我希望能够识别这一点,而不是要求您提供用户 ID,而是让您从下拉列表中选择用户名。

I've been thinking of writing a Backend-End Admin Generator for a while now. But after some searching I still can't find a solution to retrieve the relationships of the tables.

How would I go about retrieving any relationships that a table has in PHP, if this is even possible?

Update

What I want to achieve is to build a script that you point at a database. The script then lists all the tables in the database and allows you to created/edit/delete the records in these tables. But I would like to be able to find relationships and present the user with say a drop down box of all the values they can select. For example if the column "user" is linked to the table "users" on the column "id". Then I would like to be able to recognize that and instead of asking you for a ID of the user allow you to select the user's name from a drop down.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

固执像三岁 2024-11-07 00:03:08

您不会在 PHP 中寻找关系。您将使用通过 PHP 提交到数据库的 SQL 语句来查找它们。不幸的是,您需要的确切查询会因数据库而异,因为每个系统都会以不同的方式命名其系统表,并且以不同的方式存储数据(除非您要为一个数据库而不是更强大的数据库构建系统) 。

研究相关的特定 RDBMS,找到一种查看用于在架构中构建表的 SQL 命令的方法,然后解析出外键语句。可能是您最好的选择,因为定义它们的 SQL 命令相当通用,因此您将获得一些可移植性。

You won't look for relationships in PHP. You'll look for them with SQL statements submitted to the DB through PHP. Unfortunately, the exact queries you'll needs will vary from database to database as every system names their system tables something different as well as storing the data differently (unless you're going to build your system for one DB rather than something more robust).

Research the specific RDBMS in question for a way to view the SQL command used to build the tables in the schema, then just parse out the foreign key statements. Might be your best bet because the SQL commands to define them are fairly universal so you'll get some portability.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文