Yii connection, modify MySQL database and PHPUnit test connection _mysql

Source: Internet
Author: User

>>>database<<<

1. Modify protected/config/main.php

Remove the annotations to the MySQL database connection and modify the username, password, and connected database.

2. New protected/tests/unit/dbtest.php

The contents are as follows:

<?php
class Dbtest extends Ctestcase
{public
  function testconnection ()
  {
    $this-> Assertnotequals (NULL, Yii::app ()->db);
  }

3. Implementation

C:\xampp\yii\power\protected\tests> PHPUnit. \unit\dbtest.php

>>>end of datebase<<<

YII MySQL Modify database data

Learn the latest Yii framework, share some learning experience, suitable for beginners, great god please press CTRL + W

The first of these methods

The <?php/
   * $id represents a primary key and can be one or a collection.
   * $attributes represents the collection of fields to be modified.
   * $condition represent conditions.
   * $params the value passed in.
   * *
  $count = Model::model ()->updatebypk ($id, $attributes, $condition, $params);
  if ($count > 0) {
    echo ' modified successfully ';
  } else {
    echo ' modification failed ';
  }
? >

The second method

<?php
  $model = Model::model ()->findbypk ($id);
  $model->username = ' yiistudy ';
  $model->password = ' mysql ';
  $count = $model->update (Array (' username ', ' password '));
  if ($count >0) {
    echo ' modified successfully ';
  } else {
    echo ' modification failed ';
  }
? >

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.