标签:
对于某些操作的情况(例如模型的写入和更新方法),可以支持参数的自动绑定,例如:
首先需要开启DB_BIND_PARAM配置参数:
‘DB_BIND_PARAM‘ => true
然后,我们在使用
1.$Model = M(‘User‘); 2.$Model->name = ‘thinkphp‘; 3.$Model->email = ‘thinkphp@qq.com‘; 4.$Model->add();
会自动对写入的数据进行参数绑定操作。其操作等效于:
1.$Model = M(‘User‘); 2.$Model->name = ‘:name‘; 3.$Model->email = ‘:email‘; 4.$bind[‘:name‘] = ‘thinkphp‘; 5.$bind[‘:email‘] = ‘thinkphp@qq.com‘; 6.$Model->bind($bind)->add();
当然参数可以为变量:
1.$Model->username = $username;
2.$Model->password = $password;
3.$Model->email = $email;
4.$Model->phone = $phone;
5.$re=$Model->add();
标签:
原文地址:http://www.cnblogs.com/yuanwanli/p/5930382.html