分批查询

  1. foreach (ForbiddenWordsTongtu::find()->each() as $tongTu) {
  2. // coding
  3. }

/gii报错

  1. Invalid Configuration

可能的原因是 web/asset/ 目录没有写权限

常用写法

  1. // and (xx or xx)写法
  2. $obj->andWhere([
  3. 'or',
  4. ['id' => $param['company_name']],
  5. ['like', 'company_name', $param['company_name']]
  6. ]);
  7. //WHERE (`id`='100000973') OR (`company_name` LIKE '%100000973%')

连接数据新增

  1. $s = file_get_contents(__DIR__ . '/words.log');
  2. $arr = json_decode($s, true);
  3. $db = new yii\db\Connection([
  4. 'dsn' => 'mysql:host=localhost;dbname=test',
  5. 'username' => 'root',
  6. 'password' => '',
  7. 'charset' => 'utf8',
  8. ]);
  9. foreach($arr as $k => $item){
  10. $db->createCommand()->insert('forbidden_words', [
  11. 'words' => $item
  12. ])->execute();
  13. }