Yii connection modify MySQL database and phpunit test connection
- 2020-12-09 01:04:04
- OfStack
> > > database < < <
1. Modify protected/config/main. php
Remove comments on how the mysql database is connected, and change the user name, password, and the database to which it is connected.
2. New protected tests/unit/DbTest php
It is as follows:
<?php
class DbTest extends CTestCase
{
public function testConnection()
{
$this->assertNotEquals(NULL, Yii::app()->db);
}
}
3. Perform
C:\xampp\yii\power\protected\tests
>
phpunit .\unit\DbTest.php
> > > end of datebase < < <
Yii MySQL modifies the data in the database
The latest Yii framework, to share 1 learning experience, suitable for beginners, great god please press ctrl + w
// The first method
<?php
/*
* $id It's the primary key. It could be 1 I could have been 1 A collection.
* $attributes A representative is a collection of fields to modify.
* $condition Is for condition.
* $params The value passed in.
*/
$count = Model::model()->updateByPk($id,$attributes,$condition,$params);
if($count > 0) {
echo ' Modify the success ';
} else {
echo ' Modify the failure ';
}
?>
// 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 ' Modify the success ';
} else {
echo ' Modify the failure ';
}
?>