db;"; then use the "$cmd->queryAll();" method to query and return the results All rows of ."/> db;"; then use the "$cmd->queryAll();" method to query and return the results All rows of .">
Home >PHP Framework >YII >How to query the database in yii1.1
yii1.1 Method of querying the database: First specify the database to be used through the statement "$dbh = Yii::app()->db;"; then use "$cmd->queryAll() ;" method can query and return all rows in the result.
Yii 1.1 Query and operate the database
Recommended: "yii tutorial》
Specify the database connection to use:
$dbh = Yii::app()->db;
Update operation:
$sql = "upadte user set locked=1 w.h.e.r.e uid=". $uid; $cmd = $dbh->createCommand($sql); $cmd->execute();
Other operations:
$rows = $cmd->queryAll(); // 查询并返回结果中的所有行 $row = $cmd->queryRow(); // 查询并返回结果中的第一行 $column = $cmd->queryColumn(); // 查询并返回结果中的第一列 $value = $cmd->queryScalar(); // 查询并返回结果中第一行的第一个字段
The above is the detailed content of How to query the database in yii1.1. For more information, please follow other related articles on the PHP Chinese website!