Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does thinkphp5 determine whether a table exists

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "thinkphp5 how to judge the existence of the table", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "thinkphp5 how to judge whether the table exists" this article.

Methods: 1. Judge by "$axim ()-> query ('SHOW TABLES LIKE" table name "); if ($a) {existence} else {table does not exist}"; 2, judge by "$axim (table name); if ($a-> getDbError ()) {table does not exist} else {existence}".

This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.

How does thinkphp5 determine whether the table exists?

Thinkphp framework is a very easy to use and very powerful framework, it is the development habit of our people. Then when using the thinkphp framework, there is sometimes a need to determine whether a database table exists.

Here, we assume that we determine whether the users table exists:

$users = M ('users'); if ($users- > getDbError ()) {echo' data table does not exist!' ;} else {echo 'database exists!' ;}

Method 2:

$isTable = M ()-> query ('SHOW TABLES LIKE "table_name'); if ($isTable) {echo 'table exists';} else {echo 'table does not exist';} above is all the content of the article" how to determine whether a table exists or not ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report