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  >  Article  >  PHP Framework  >  How to query the database in yii1.1

How to query the database in yii1.1

藏色散人
藏色散人Original
2020-07-20 09:47:142881browse

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.

How to query the database in yii1.1

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn