YII database Query

Source: Internet
Author: User
Tags yii

        $userModel = User::model ();        $userModel->count ();        $userModel->count ($condition);        $userModel->count ($condition, $params);        $userModel->countbyattributes ($attributes);        $userModel->countbyattributes ($attributes, $condition);        $userModel->countbyattributes ($attributes, $condition, $params);        $userModel->countbysql ($sql);              $userModel->countbysql ($sql, $params);        $userModel = User::model ();        $userModel->find ();        $userModel->find ($condition);                $userModel->find ($condition, $params);        $userModel-&GT;FINDBYPK ($PK);        $userModel->findbypk ($PK, $condition);        $userModel->findbypk ($PK, $condition, $params);        $userModel->findbyattributes ($attributes);        $userModel->findbyattributes ($attributes, $userModel);                $userModel->findbyattributes ($attributes, $userModel, $params);    $userModel->findbysql ($sql);    $userModel->findbysql ($sql, $params); The return value is an array of objects, and NULL is returned if NULL. For a record $findResult = $userModel->find (' Islock =: Islock and phone_status=:p hone_status ', Array (': islock ' = 1, '        :p hone_status ' =>1)); Phone_status, Echo $findResult.        <br/> ";        Var_dump ($findResult->attributes);        if ($userModel->find (' user_id=260 ')) {echo ' find ';        }else{echo ' no find '; }


Explanation: A record is returned above assuming that you want to return more than one data FindAll class

$condition is the general SQL inside WHERE clause, a character channeling

$params is an array that assigns a value to a placeholder

Find out all the data:

        $userinfo = $userModel->findallbyattributes (Array (' Islock ' =>1, ' phone_status ' = 0));        foreach ($userinfo as $k = + $v) {            echo $v->user_id.  $userinfo [$k][user_id]. " <br/> ";        }

Visible. The result is a two-dimensional array.

Talk Cdbcriteria and model objects in combination

        $criteria = new Cdbcriteria;         if ($condition) $criteria->condition = $condition;        $criteria->offset = $offset;        if ($order) $criteria->order = $order;        if ($limit! = "All") $criteria->limit = $limit;        if (!empty ($more _criteria)) {            $criteria->mergewith ($more _criteria);        }        $Model = new $modelName;        if (!empty ($with _array)) {            $result = $Model->with ($with _array)->findallbyattributes ($attributes, $ criteria);        } else{            $result = $Model->findallbyattributes ($attributes, $criteria);        }




YII database Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.