Home > Article > Backend Development > How to use the table method in thinkphp?
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?
Isn’t it easier to write like this? --> M("User")
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?