傳統的sql與ThinkPHP中的sql相比較 以user表為例
<span>$user</span>=M('user'<span>); </span>1: SELECT * FROM user----------<span>$user</span>-><span>select(); </span>2: SELECT* FORM user WHERE id=2---------<span>$user</span>->find(2<span>); </span>3: SELECT username FORMuser-----<span>$user</span>->field('username')-><span>select();<br>4: DELETE FORM username WHEREid=2------$user->delete(2);<br>5: UPDATE user SET username='newUsername' WHERE id=2-------$data['username']='newUsername' $user->save($data);<br>6: INSERT INTO user (name,password)VALUES('php','phpPwd')------$data['name']='php' $data['password']='phpPwd' $user->add($data); </span>
以上就介紹了ThinkPHP的資料庫存取的簡單操作,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。