Heim  >  Artikel  >  Datenbank  >  Yii 连接、修改 MySQL 数据库及phpunit 测试连接_MySQL

Yii 连接、修改 MySQL 数据库及phpunit 测试连接_MySQL

WBOY
WBOYOriginal
2016-05-27 13:45:45884Durchsuche

>>>database

1. 修改 protected/config/main.php

去掉mysql数据库连接方式的注释,并且修改用户名,密码以及连接的数据库。

2. 新建 protected/tests/unit/DbTest.php

内容如下:

<&#63;php
class DbTest extends CTestCase
{
  public function testConnection()
  {
    $this->assertNotEquals(NULL, Yii::app()->db);
  }
}

3. 执行

  C:\xampp\yii\power\protected\tests> phpunit .\unit\DbTest.php

>>>end of datebase

Yii MySQL修改数据库的数据

最新学习Yii框架,分享一些学习心得,适合初学者,大神请按ctrl + w

//第一种方法

<&#63;php
  /*
   * $id 代表主键,可以是一个也可以是一个集合。
   * $attributes 代表是要修改的字段的集合。
   * $condition 代表条件。
   * $params 传入的值。
   */
  $count = Model::model()->updateByPk($id,$attributes,$condition,$params);
  if($count > 0) {
    echo '修改成功';
  } else {
    echo '修改失败';
  }
&#63;>

//第二种方法

<&#63;php
  $model = Model::model()->findByPk($id);
  $model->username = 'yiistudy';
  $model->password = 'mysql';
  $count = $model->update(array('username','password'));
  if($count>0) {
    echo '修改成功';
  } else {
    echo '修改失败';
  }
&#63;>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn