0%

数据库插入异常

mySql报错:

1
Column count doesn't match value count at row 1

网上给出的原因一致是:数据的个数、类型不符,或者就是中英文符号混用了。折腾了很久,终于发现是触发器导致了异常!!!

1
2
3
4
CREATE TRIGGER add_audit AFTER INSERT ON equipment
FOR EACH ROW BEGIN
insert into audit_equipment VALUES(new.eqpid,user(),now(),1);
END

怎么回事呢——改了audit_equipment表的属性,但忘了改equipment中的触发器,实际上是插入audit_equipment表时失败了,但是报错时就会显示equipment的插入失败。

在MySQL中CHECK约束是无效的

可以把对日期的约束写在yii中,也可以用触发器代替;

含有事务应用的删除操作

path:E:\Xampp\htdocs\yii2\sport_equipment\common\models\Equipment.php

public function delete()

​ {

​ if (!$this->isTransactional(self::OP_DELETE)) {

​ return $this->deleteInternal();

​ }

$db = Yii::$app->db;

$transaction = $db->beginTransaction();

try {

​ $db->createCommand(‘UPDATE post SET status=1 WHERE id=1’)->execute();

​ $result = $this->deleteInternal();

​ if ($result === false) {

​ $transaction->rollBack();

​ } else {

​ $transaction->commit();

​ }

​ } catch(\Exception $e) {

​ $transaction->rollBack();

​ throw $e;

​ } catch(\Throwable $e) {

​ $transaction->rollBack();

​ throw $e;

​ }

​ }

mySql获取当前时间
1
2
3
4
5
6
7
SELECT current_date(), curdate(), curdate() + 0;      # '2018-03-09' '2018-03-09'  20180309
SELECT current_time(), curtime(), curtime() + 0; # 16:49:41 16:49:41 164941
SELECT current_time(2), curtime(2), curtime(2) + 0; # 16:50:50 16:50:50 165050.01

SELECT now(), now(3), now(6);

2018-03-09 16:53:51 2018-03-09 16:53:51.163 2018-03-09 16:53:51.163791
数据库插入时报错

The SQL being executed was: INSERT INTO equipment (eqpid, catid) VALUES (‘c2002’, ‘c2’)

1
2
3
4
5
6
Error Info: Array
(
[0] => 21S01
[1] => 1136
[2] => Column count doesn't match value count at row 1
)

Caused by: PDOException

SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn’t match value count at row 1

Writing

Directions: For this part, you are allowed 30 minutes to write an essay on the importance of building trust between businesses and consumers. You can cite examples to illustrate your views. You should write at least 150 words but no more than 200 words.

The Importance of Building Trust Between Businesses and Consumers

Today, in the context of this era featured by increasing commercialization and digitalization, mutually-trusted relations between businesses and consumers appear to be particularly important.

As for me, businesses should take a leading role in establishing the trust relationship: to be honest with their consumers. Firstly, if a business has a dishonest attitude toward its customers, the customers will lack purchasing confidence in its goods or services, which will bring huge economic loss to the business.

What’s worse, the adverse side effect of such dishonesty can endanger the business and it is impossible to recover. The collapse of Sanlu Mike Power Company is a testament to this. Moreover, the incident of poisonous milk has exerted devasting consequences on the whole milk powder market. Besides, because of the proliferation of counterfeit goods, more consumers lose confidence in domestic products, and then they have no alternative but to resort to foreign brands, which is one reason why cross-border online shopping is gaining more and more popularity in China.

Therefore, it is high time for us to strengthen the importance of maintaining trust between businesses and consumers to promote the healthy development of the whole social economy.

notes
  • business 企业;individual businesses个体工商户;

The company was a family business.

这家公司是一个家族企业。

  • consumer&customer

A consumer is a person who buys things or uses services. 消费者

A customer is someone who buys goods or services, especially from a shop. 顾客

  • context: 环境;上下文;来龙去脉;

We are doing this work in the context of reforms in the economic, social and cultural spheres(领域).

  • be featured by … 以…为特征
  • adverse: 不利的,相反的,敌对的

adverse effect 不利影响,副作用

adverse weather恶劣天气

  • testament: 确实的证明,遗嘱,圣约
  • exert: 施加影响,运用权威;耗费精力

exert oneself 努力;尽力

exert an influence on 对…产生影响

Don’t exert yourself unnecessarily.不要无谓地耗费自己的精力。

  • proliferation: 增殖;扩散;分芽繁殖

Proliferation and use of open source assets.开放源码资产的使用和扩散。

  • counterfeit: [][][adj.]伪造的,假冒的,假装的,虚假的;[v.]伪造,假装,酷似;[n.]仿冒品

conunterfeit products 假货

  • resort to: 依靠,诉诸,常去

resort to unjust means 借助不正当的手段

If other means fail, we shall resort to force. 如果其他手段均失败,我们就将诉诸武力。

  • 商业化和数字化 commercialization and digitalization

文件存在,但显示404,如图:

yii404

http://localhost:8081/yii2/sport_equipment/backend/web/index.php?r=audit_equipment%2Findex这是最后正确的路由,最开始试了audit_Equipment,auditEquipment,甚至还有audit-Equipment,文件就在那儿,咋就404呢?最后试出来,得用小写字母——“audit_equipment”,其实具体原理我也不懂。另外补充:Model的命名,只能是字母或写划线:“Only word characters and backslashes are allowed.”

显示数据库中的视图

在访问http://localhost:8081/yii2/sport_equipment/frontend/web/时,报错:

Invalid Configuration – yii\base\InvalidConfigException
The ‘label’ option is required.

我想做成:当前用户为游客时,不显示vborrow,当前用户登录后,vborrow才显示出来,可以点击,尝试之后,代码如下:

Path: frontend\views\layouts\main.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
   <?php
NavBar::begin([
'brandLabel' => Yii::$app->name,
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
//这里显示的是游客和已登录用户都能看到的内容
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
//只有游客才能看见的内容
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
//只有已登录用户才能看见的内容,这里如果格式不对,会出现“The 'label' option is required.”的错误
$menuItems[] = ['label' => 'Vborrow', 'url' => ['/vborrow/index']];
$menuItems[] = ['label' => 'Vstudent', 'url' => ['/vstudent/index']];
$menuItems[] = ['label' => 'Vteacher', 'url' => ['/vteacher/index']];
$menuItems[] ='<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>';
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>

因为视图没有主键,所以无法用gii生成CURD,所以复制了其他数据表的控制器和视图文件,在上边作了修改。

mysql的外键约束

InnoDB拒绝任何试着在子表创建一个外键值而不匹配在父表中的候选键值的INSERT或UPDATE操作(InnoDB是MySQL的数据库引擎之一)。有五种外键约束:

  • cascade:从父表中删除或更新,且自动删除或更新自表中匹配的行。ON DELETE CASCADE和ON UPDATE CASCADE
  • set null:从父表删除或更新行,并设置子表中的外键列为NULL。ON DELETE SET NULL和ON UPDATE SET NULL
  • no action: InnoDB拒绝对父表的删除或更新操作。
  • restrict(默认值):拒绝对父表的删除或更新操作。NO ACTION和RESTRICT都一样,删除ON DELETE或ON UPDATE子句。(一些数据库系统有延期检查,并且NO ACTION是一个延期检查。在MySQL中,外键约束是被立即检查的,所以NO ACTION和RESTRICT是同样的)。
  • set default:InnoDB拒绝包含ON DELETE SET DEFAULT或ON UPDATE SET DEFAULT

在yii框架生成的表单中,若对子表中外键属性进行插入时,输入空值,点保存会报错,修改方法为:

在model中重写yii\base\Model::rule()方法,设置外键属性栏为必填(required):

1
2
3
4
5
6
7
8
9
10
public function rules()
{
return [
// name,email,subject 和 body 特性是 `require`(必填)的
[['name', 'email', 'subject', 'body'], 'required'],

// email 特性必须是一个有效的 email 地址
['email', 'email'],
];
}
输入固定长度的字符串

起因是,我就想让学号是7位的,但是在数据库设成char(7),然后输入长度小于7的,它就自动在后面补空格了,所以还是要从yii框架这边的输入规则下手,和上面的操作一样,增加min规则:

1
[['prsid'], 'string', 'max' => 7,'min'=> 7]

min_string

yii框架创建下拉列表
1
2
3
4
5
6
7
8
/* @var $form yii\widgets\ActiveForm */

echo $form->field($model, 'category')->dropdownList([
1 => 'item 1',
2 => 'item 2'
],
['prompt'=>'Select Category']
);

但是我现在觉得,我需要的“性别”那一栏,单选列表更合适喔,所以:

yii框架创建单选列表
1
2
3
4
5
6
/* @var $form yii\widgets\ActiveForm */

echo $form->field($model, 'category')->radioList([
1 => 'radio 1',
2 => 'radio 2'
]);

前面是需要存入数据库的字段,后面是显示的文字,具体地:

1
2
3
4
5
6
7
8
9
<?= $form->field($model, 'sex')->radioList(['m'=>'男','f'=>'女']) ?>

<?= $form->field($model, 'ptype')->radioList([1=>'学生',2=>'教职工']) ?>

<?= $form->field($model, 'degree')->dropdownList([
'本科生' => '本科生',
'硕士' => '硕士',
'博士' => '博士',
]); ?>

1557199635204

index页面明明是有的,怎么就404了?!!

多项式的系数表示和点值表示,在计算多项式的数乘、加法、乘法时各有优势,利用快速傅里叶变换(FFT),在O(nlogn)的时间复杂度内进行两中表示方法的转化,可以有效降低程序的复杂度。以卷积为例,如下图所示1557145462556

利用下面这篇博客:快速傅里叶变换(FFT)详解,学习了FFT的写法,代码中把实系数都转化成复数,统一进行复数上的运算。IFFT(逆运算)和FFT可以放一起,用复数的虚部(+/- i)就可以区分两种不同的运算,至于原理,属于数学属于数学证明了(关键我不会)。rev数组的作用没有看懂,下次要来这里补上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
struct cn
{
double x, y;
cn(double x = 0, double y = 0) :x(x), y(y) {}
}a[300005], b[300005], c[300005];
cn operator + (const cn &a, const cn &b) { return cn(a.x + b.x, a.y + b.y); }
cn operator - (const cn &a, const cn &b) { return cn(a.x - b.x, a.y - b.y); }
cn operator * (const cn &a, const cn &b) { return cn(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x); }
void fft(cn a[], int n, int l, int f)
{
int* rev=new int[n + 5];
rev[0] = 0;
for (int i = 1; i<n; i++) {
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);
if (i<rev[i]) swap(a[i], a[rev[i]]);
}
for (int i = 1; i<n; i <<= 1) {
cn wi(cos(pi / i), f*sin(pi / i));
for (int j = 0; j<n; j += i * 2) {
cn w(1, 0);
for (int k = 0; k<i; k++) {
cn x = a[j + k], y = w * a[j + k + i];
a[j + k] = x + y;
a[j + k + i] = x - y;
w = w * wi;
}
}
}
if (f == -1)
for (int i = 0; i<n; i++) {
a[i].x /= n; a[i].y /= n;
}
}
int main()
{
int n, m;
scanf_s("%d%d", &n, &m); n++; m++;
for (int i = 0; i<n; i++) scanf_s("%lf", &a[i].x);
for (int i = 0; i<m; i++) scanf_s("%lf", &b[i].x);
int l = 0, N = 1;
while (N<n + m - 1) N <<= 1, l++;
fft(a, N, l, 1);
fft(b, N, l, 1);
for (int i = 0; i<N; i++) c[i] = a[i] * b[i];
fft(c, N, l, -1);
for (int i = 0; i<n + m - 1; i++) printf("%d ", (int)(c[i].x + 0.5));
system("pause");
return 0;
}

Writing

Directions: For this part, you are allowed 30minutes to write an essay on the importance ofbuilding trust between teachers and students. You can cite exa mples to illustrate yourviews. You should write at least 150 words but no mo re than 200 words.

The Importance of Building Trust between Teachers and Students

A good relationship between a teacher and a student can have a major influence on a kid’s development, and trust is crucial and indispensable in maintaining the relationship.

To begin with, only when a student believes in his or her student is he or she willing to learn from the teacher or look to the teacher for guidance and support. In reality, too many students are weary of study and drop out of school only because they dislike their teachers, which may transform their whole life. Besides, a teacher who has the full trust of his or her students is more motivated to help them improve the consciousness and initiative of learning, which in turn benefits the students most. However, the credibility between teachers and students is not something that can built in a day. On the on hand, teachers should comprehend the students’ actual demands and offer timely help. On the other hand, students should always be respectful to their teachers.

All in all, trust in a teacher-student relationship is a must to achieve effective teaching and learning.

notes

作文结构:综述、分两方面写好处、分两方面写怎么做、总结

indispensible: 不可或缺的

initiative: [n.]主动权,首创精神,新方案;[adj.]主动的,自发的。We have the initiative; we intend to keep it.

credibility: 可信性 The police have lost their credibility.

对孩子的发展有重要影响;维持关系;只有当…才…;向某人寻求帮助;疲于…;辍学;自觉性,主动性;

Translation

中国目前拥有世界上最大最快的高速铁路网。高铁列车的运行速度还将继续提升,更多的城市将修建高铁站。高铁大大缩短了人们出行的时间。相对飞机而言,高铁列车的突出优势在于准时,因为基本不受天气或交通管制的影响。高铁极大地改变了中国人的生活方式。如今,它已经成了很多人商务旅行的首选交通工具。越来越多的人也在假日乘高铁外出旅游。还有 不少年轻人选择在一个城市工作而在邻近城市居住,每天乘高铁上下班。

China now has the largest and fastest high-speed rail network in the world. The speed of the CRH(China Railway High-Speed) train will continue to increase and more cities will build high-speed rail station. The CRH train has greatly reduced people’s travel time. Compared with the airplane, the outstanding advantage of the CRH train is punctuality, because it is basically not affected by weather or traffic control. It has transformed the way people live and become the favorite option for business travelers today. More and more people also travel by CRH during holidays. Many young people choose to work in one city but live in a nearby one since they can commute by CRH train every day.

notes

rail: short for railway

transform: change or convert sth. into … 使改变,使转换 transform into …

basically not:基本不 My article is basically not meeting the request of English.

commute: 通勤 commute between 经常往来于两地之间

翻译

过去,拥有一辆私家车对大部分中国人而言是件奢侈的事。如今,私家车在中国随处可见。
汽车成了人们生活中不可或缺的一部分,他们不仅开车上下班,还经常驾车出游。有些城市
的汽车增长速度过快,以至于交通拥堵和停车位不足的问题日益严峻,这些城市的市政府不
得不出台新规,限制上路汽车的数量。由于空气污染日益严重,现在越来越多的人选择购买 新能源汽车,中国政府也采取了一些措施,支持新能源汽车的发展。

In the past. Owning a private car was a luxury thing for most Chinese. Nowadays, private cars can be seen everywhere in China. Cars have become an integral part of people’s life: they not only drive to and from work, but also travel around by car. Spikes in ownership have resulted in more prevalent traffic gridlock and inadequate parking space in some cities, which has prompted local governments to roll out new rules to rein in the number of cars on the road. As air pollution gets more serious, now more and
more people choose to buy new energy vehicles. The Chinese government has taken some measure to support the development of new energy vehicles.

Notes:

Integral: forming a necessary part of something. Eg: Vegetables are an integral part of our diet.

Gridlock[un.]: a situation in which streets in a city are so full of cars that they can’t move.

Roll out : 铺开,滚出,推出(新产品、服务等),实行(新制度),开展

You should learn to rein in your temper.

写作

Directions: For this part, you are allowed 30minutes to write an essay on the importance ofbuilding trust between employers and employees. You can cite examples to illustrate yourviews. You should write at least 150 words but no more than 200 words.

The Importance of Building Trust Between Employers and Employees

It is an undeniable fact that trust can lay a solid foundation for commercial activities. Therefore, building trust between employers and employees plays a crucial role in boosting an organization.

To begin with, as the saying goes, the best bosses understand the art of delegation. If a boss believes in his people and tries his best to delegate instead of micromanaging, this kind of belief can drive him to create an environment where employees would have passion for work and work efficiently. Next, with trust, employers and employees can achieve mutual consensus, build harmonious cooperation and have effective communication, which is beneficial to create a pleasant working atmosphere. In this way, not surprisingly, the two parties can directly prompt the rapid progress of the organization and indirectly spur continuous development of the individuals.

Taking into account what we have discussed above, we may safely arrive at a conclusion that it is sensible for both employers and employees to keep in mind that mutual trust contributes to realizing a win-win situation.

https://www.cnblogs.com/logon/p/3748020.html

A inner join B on …产生A和B的交集

A full outer join B on …产生A和B的并集,对于没有匹配的记录,记为null

A left (outer) join B on …产生表A的完全集,而表B中匹配的的则有值,没有匹配的为null

mysql的常用engine是InnoDB,在该引擎下使用check约束是无效的。但是可以通过使用触发器来做到检查约束的效果,通过使用触发器使mysql具有检查约束的功能。

存储过程十一组SQL语句集,可以实现复杂的逻辑功能。触发器也是一组SQL集,但存储过程是主动调用的,且功能更强大,触发器石某事件触发后自动调用。

有输入输出参数,可以声明变量,有if/else, case,while等控制语句,通过编写存储过程,可以实现复杂的逻辑功能;函数的普遍特性:模块化,封装,代码复用;速度快,只有首次执行需经过编译和优化步骤,后续被调用可以直接执行,省去以上步骤;

mysql存储过程中的if语句:

1
2
3
IF expression THEN 
statements;
END IF;

如果上述表达式(expression)计算结果为TRUE,那么将执行statements语句,否则控制流将传递到END IF之后的下一个语句.

IF ELSE语句的语法结构:

1
2
3
4
5
IF expression THEN
statements;
ELSE
else-statements;
END IF;

如果要基于多个表达式有条件地执行语句,则使用IF ELSEIF ELSE语句,它的语法结构如下:

1
2
3
4
5
6
7
8
IF expression THEN
statements;
ELSEIF elseif-expression THEN
elseif-statements;
...
ELSE
else-statements;
END IF;

mysql declare和set定义变量,除了一个不加@和一个加@这个区别之外,还有以下区别:

declare用来定义局部变量

@用来定义会话变量

declare变量的作用范围同编程里面类似,在这里一般是在对应的begin和end之间。在end之后这个变量就没有作用了,不能使用了。这个同编程一样。

另外有种变量叫做会话变量(session variable),也叫做用户定义的变量(user defined variable)。这种变量要在变量名称前面加上“@”符号,叫做会话变量,代表整个会话过程他都是有作用的,这个有点类似于全局变量一样。这种变量用途比较广,因为只要在一个会话内(就是某个应用的一个连接过程中),这个变量可以在被调用的存储过程或者代码之间共享数据。

sql server中变量要先申明后赋值:

局部变量用一个@标识,全局变量用两个@(常用的全局变量一般都是已经定义好的);

申明局部变量语法:declare @变量名 数据类型;例如:declare @num int;

赋值:有两种方法式(@num为变量名,value为值)

set @num=value; 或 select @num=value;

如果想获取查询语句中的一个字段值可以用select给变量赋值,如下:

select @num=字段名 from 表名 where ……

mysql中变量不用事前申明,在用的时候直接用“@变量名”使用就可以了。

第一种用法:set @num=1; 或set @num:=1; //这里要使用变量来保存数据,直接使用@num变量

第二种用法:select @num:=1; 或 select @num:=字段名 from 表名 where ……

注意上面两种赋值符号,使用set时可以用“=”或“:=”,但是使用select时必须用“:=赋值”

MySQL触发器不能执行SELECT返回结果

过拟合问题

线性回归、逻辑回归(分类):

欠拟合—有高偏差

过度拟合—具有高方差,变量太多,过度拟合数据而无法泛华

解决过拟合方法:

人工减少变量数量,或使用模型选择算法(自动),缺点:舍弃了一部分信息

选择正则化,减少量级,保留所有特征变量

####正则化

加入惩罚,扩大参数值的影响,参数会尽可能小,使模型简化。

$J(\theta)=\frac{1}{2m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)} )^2+1000\theta_3^2+1000\theta_4^2$

在实际问题中很难判断哪些特征比较重要, 所以在正则化中,对每一个参数(除了第一个)参数进行惩罚, 将代价函数改为:

$J(\theta)=\frac{1}{2m}\left[\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)} )^2+\lambda\sum_{i=1}^n\theta_j^2\right]$

$\lambda$叫做正则化参数(Regularization Parameter).$\lambda$的作用就是在”更好地拟合数据”和”防止过拟合”之间权衡。惩罚程度过大,会导致欠拟合。

正则化线性回归

梯度下降

$\theta=(X^TX+\lambda\begin{bmatrix} 0&0&0&0&…&0\ 0&1&0&0&…&0\ 0&0&1&0&…&0\ 0&0&0&1&…&0\ 0&0&0&0&…&0 \ 0&0&0&0&…&1 \end{bmatrix})^{-1}X^Ty$

对于正则化后的正规方程, 只要λ>0λ>0, 括号里的那一项总是可逆的。

改进梯度算法和高级算法,以应用到正则化逻辑回归中。