数据库表中新建字段满足条件时,赋值表中其他字段

情景描述:项目中,存在在表中添加新字段,并且在满足一定条件时将表中其他字段的值赋给该字段。不必查询出来后,在为其赋值。

代码:

//创建sql语句
$sql = 'update table_name set new_field1 = field1, new_field2 = field2 where ';
$sql .= "new_field1 is null and new_field2 is null and (field1和field2满足的条件)";

//实例化数据库:http://document.thinkphp.cn/manual_3_2.html#sql_query
$db = new \Think\Model();
$db->execute($sql);

猜你喜欢

转载自blog.csdn.net/yixu0534/article/details/80882284
今日推荐