如何使用php从数据库中获取最后创建的表名

发布于 2024-12-26 09:38:59 字数 267 浏览 5 评论 0原文

我想使用 PHP 从 MySQL 数据库获取最后创建的表名。

我也使用了查询,但我无法获得任何值。这是查询:

"select table_name from information_schema.tables where table_schema = 'databse_name' order by create_time desc limit 1"

当我使用它时,我从本地系统获取值,但没有从客户端数据库获取值。 我的查询有什么错误?

I want to get the last created table name from a MySQL database using PHP.

I also used a query, but I cant to get any value. This is the query:

"select table_name from information_schema.tables where table_schema = 'databse_name' order by create_time desc limit 1"

When I am using this I get value from local system but not get value from client's database.
What is the mistake in my query?

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

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

发布评论

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

评论(2

触ぅ动初心 2025-01-02 09:38:59

如果我理解正确,您的查询在本地计算机上可以正常工作,但在实时环境中却不能?

或许现环境中的MySQL用户访问权限不足?尝试在实时环境 MySQL 数据库中执行类似的操作:

GRANT SELECT ON information_schema.tables TO `user`@`localhost`

并将 user 替换为正确的用户名,如果您连接到 localhost 外部的数据库,也可能将 localhost 部分替换。

If I understood correctly, your query works fine on your local machine, but in the live environment it doesn't?

Perhaps the MySQL user in the live environment has insufficient access? Try executing something like this in the live environment MySQL database:

GRANT SELECT ON information_schema.tables TO `user`@`localhost`

And replace user to the correct user name, also perhaps the localhost part if you connect to a database outside localhost.

此刻的回忆 2025-01-02 09:38:59

您有要访问的数据库的权限吗?

请尝试一下:

select create_time, table_name, table_schema 
from information_schema.tables 
where table_schema not in ('mysql')
and table_schema not like '%_schema'  
order by create_time desc 

您是否得到结果,如果您没有得到您所引用的数据库的结果,那么它一定是权限问题。

Do you have permiossion for the databases you want to access?

Try this please:

select create_time, table_name, table_schema 
from information_schema.tables 
where table_schema not in ('mysql')
and table_schema not like '%_schema'  
order by create_time desc 

Do you get a result, if you don't get a result for the database you where referring to, then it must be the permissions.

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