当前位置:Gxlcms > PHP教程 > ThinkPHP的数据库访问的简单操作

ThinkPHP的数据库访问的简单操作

时间:2021-07-01 10:21:17 帮助过:25人阅读

              传统的sql与ThinkPHP中的sql相比较 以user表为例

  1. <span>$user</span>=M('user'<span>);
  2. </span>1: SELECT * FROM user----------<span>$user</span>-><span>select();
  3. </span>2: SELECT* FORM user WHERE id=2---------<span>$user</span>->find(2<span>);
  4. </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教程有兴趣的朋友有所帮助。

人气教程排行