Home > PHP Framework > YII > How to query the database in yii1.1

How to query the database in yii1.1

藏色散人
Release: 2020-07-20 09:47:14
Original
2976 people have browsed it

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;
Copy after login

Update operation:

$sql = "upadte user set locked=1 w.h.e.r.e uid=". $uid;
$cmd = $dbh->createCommand($sql);
$cmd->execute();
Copy after login

Other operations:

$rows = $cmd->queryAll();      // 查询并返回结果中的所有行
$row = $cmd->queryRow();       // 查询并返回结果中的第一行
$column = $cmd->queryColumn(); // 查询并返回结果中的第一列
$value = $cmd->queryScalar();  // 查询并返回结果中第一行的第一个字段
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template