![]() |
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
#1
IP: 153.99.77.173
|
|||
|
|||
|
初学ThinkPHP的时候,很多人都对execute()和query()方法的区别搞不懂,本文就此浅析二者的区别。
大家都知道,ThinkPHP中execute()和query()方法都可以在参数里直接输入SQL语句。但是不同的是execute()通常用来执行insert或update等SQL语句,而query常用来执行select等语句。 execute()方法将返回影响的记录数,如果执行SQL的select语句的话,返回的结果将是表的总记录数: Code:
$model = M( "MyTable" ); $result = $model ->execute( 'update MyTable set name=aaa where id=11'); //将返回总行数 Code:
$model = M( "MyTable" ); $result = $model ->query( 'select * from MyTable' ); //将返回array() |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|