欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-04-26 19:50:20
...

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

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

     

$user=M('user');
1: SELECT * FROM user----------$user->select();
2: SELECT* FORM user WHERE id=2---------$user->find(2);
3: SELECT username FORMuser-----$user->field('username')->select();
4: DELETE FORM username WHEREid=2------$user->delete(2);
5: UPDATE user SET username='newUsername' WHERE id=2-------$data['username']='newUsername' $user->save($data);
6: INSERT INTO user (name,password)VALUES('php','phpPwd')------$data['name']='php' $data['password']='phpPwd' $user->add($data);