Home  >  Article  >  Backend Development  >  How to use the table method in thinkphp?

How to use the table method in thinkphp?

WBOY
WBOYOriginal
2016-09-26 08:40:131321browse

What I found online is basically the same as what is written in the document:
http://document.thinkphp.cn/m...

<code>例如:
$Model->table('think_user')->where('status>1')->select();
也可以在table方法中指定数据库,例如:
$Model->table('db_name.think_user')->where('status>1')->select();
复制代码
table方法指定的数据表需要完整的表名,但可以采用下面的方式简化数据表前缀的传入,例如:
$Model->table('__USER__')->where('status>1')->select();
会自动获取当前模型对应的数据表前缀来生成 think_user 数据表名称。
</code>

But when I use
M()->table("tp_user)->select();
an error will be reported. The sql statement in the error message includes the table prefix in the configuration file, but When using the table method, don’t you need to add the table prefix yourself? Why does it still read the prefix in the configuration file after I add the prefix?

In addition, the way of omitting the prefix written in the document: M()->table("__USER__") is it necessary to use it in actual development?

Isn’t it easier to write like this? --> M("User")

Reply content:

What I found online is basically the same as what is written in the document:

http://document.thinkphp.cn/m...

<code>例如:
$Model->table('think_user')->where('status>1')->select();
也可以在table方法中指定数据库,例如:
$Model->table('db_name.think_user')->where('status>1')->select();
复制代码
table方法指定的数据表需要完整的表名,但可以采用下面的方式简化数据表前缀的传入,例如:
$Model->table('__USER__')->where('status>1')->select();
会自动获取当前模型对应的数据表前缀来生成 think_user 数据表名称。
</code>
But when I use

M()->table("tp_user)->select();
an error will be reported. The sql statement in the error message includes the table prefix in the configuration file, but When using the table method, don’t you need to add the table prefix yourself? Why does it still read the prefix in the configuration file after I add the prefix?
In addition, the way of omitting the prefix written in the document: M()->table("__USER__") is it necessary to use it in actual development?

Isn’t it easier to write like this? --> M("User")

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn