DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_update`(IN `newcatid` CHAR(2), IN `newprice` FLOAT) DETERMINISTIC BEGIN IF(select count(*) from borrow,equipment,category where borrow.eqpid=equipment.eqpid and equipment.catid=category.catid and category.catid=newcatid group by category.catid )<5 THEN UPDATE category set price=newprice where catid=newcatid; ELSE UPDATE category set price=(newprice*0.9) where catid=newcatid; end if; select newcatid,newprice; END$$ DELIMITER ;
$post = Yii::$app->db->createCommand('SELECT * FROM post WHERE id=:id AND status=:status') ->bindValue(':id', $_GET['id']) ->bindValue(':status', 1) ->queryOne();
#或使用:
$params = [':id' => $_GET['id'], ':status' => 1];
$post = Yii::$app->db->createCommand('SELECT * FROM post WHERE id=:id AND status=:status') ->bindValues($params) ->queryOne(); $post = Yii::$app->db->createCommand('SELECT * FROM post WHERE id=:id AND status=:status', $params) ->queryOne();
bindValue():绑定一个参数值 bindValues():在一次调用中绑定多个参数值
可以使用不同参数多次执行。
执行非查询语句,即不取回数据的语句,调用excute()方法,返回执行 SQL 所影响到的行数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Yii::$app->db->createCommand('UPDATE post SET status=1 WHERE id=1') ->execute();