Home  >  Article  >  Backend Development  >  浅析ThinkPHP中execute和query方法的区别_php实例

浅析ThinkPHP中execute和query方法的区别_php实例

WBOY
WBOYOriginal
2016-06-07 17:19:00799browse

初学ThinkPHP的时候,很多人都对execute()和query()方法的区别搞不懂,本文就此浅析二者的区别。
大家都知道,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 * from  MyTable' ); //将返回array()
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