thinkphp中execute的用法是什么
2022-11-24 11:02:51
146
{{single.collect_count}}

在thinkphp中,execute()方法可以在参数中直接输入SQL语句,该方法用于执行insert或update等SQL语句,返回的结果就是SQL语句影响的记录数,语法为“$model ->execute(SQL语句)”。

php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

本文操作环境:Windows10系统、ThinkPHP5版、Dell G3电脑。

thinkphp中execute的用法是什么

ThinkPHP中execute()和query()方法都可以在参数里直接输入SQL语句。但是不同的是execute()通常用来执行insert或update等SQL语句,而query常用来执行select等语句。

execute()方法将返回影响的记录数,如果执行SQL的select语句的话,返回的结果将是表的总记录数:

代码如下:

$model = M( "MyTable" );$result = $model ->execute( 'update MyTable set name=aaa where id=11'); //将返回总行数
登录后复制

query()方法将返回数据集:

代码如下:

$model = M( "MyTable" );$result = $model ->query( 'select * fromMyTable' ); //将返回array()
登录后复制

推荐学习:《PHP视频教程

以上就是thinkphp中execute的用法是什么的详细内容,更多请关注php中文网其它相关文章!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}