TP5.x——update更新成功但是返回是0
时间: 2023-11-19 11:05:13 浏览: 27
在TP5.x中,update方法返回值为影响的行数,如果返回值为0表示更新操作未成功。可能的原因有:
1. 更新的数据没有发生变化,即要更新的数据和数据库中的数据是一样的。
2. 更新的条件没有匹配到任何数据,即更新的条件不满足任何一条数据。
3. 更新操作出现异常,可以通过try...catch语句块捕获异常信息进行排查。
建议检查以上问题并进行相应的处理。
相关问题
mysql字段追加 tp_TP5数据库操作——增加
要在 MySQL 数据库中的表中增加字段,可以使用 ALTER TABLE 语句来实现。在 ThinkPHP 5 中,可以使用 Query 对象进行数据库操作。
以下是在 TP5 中增加 MySQL 表字段的示例代码:
```php
// 获取数据库连接对象
$db = \think\Db::connect();
// 执行 SQL 语句,增加字段
$sql = "ALTER TABLE `表名` ADD COLUMN `字段名` varchar(50) NOT NULL DEFAULT '' COMMENT '字段注释'";
$db->execute($sql);
```
其中,`表名` 是要增加字段的表名,`字段名` 是要增加的字段名,`varchar(50)` 是字段类型和长度,`NOT NULL` 表示该字段不允许为空,`DEFAULT ''` 表示该字段的默认值为空字符串,`COMMENT` 是该字段的注释信息。
执行上述代码后,就可以在指定的表中增加一个新的字段了。
修改这个函数,要实现防止连续点按 while (1) { tp_dev.scan(0); if (tp_dev.sta & TP_PRES_DOWN) { //触摸屏被按下 if (tp_dev.x[0] > 0 && tp_dev.x[0] < 130 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 0 && tp_dev.x[0] < 130 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i < 5) { password[i++] = '1'; } } else if (tp_dev.x[0] > 130 && tp_dev.x[0] < 260 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 130 && tp_dev.x[0] < 260 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i < 5) { password[i++] = '2'; } } else if (tp_dev.x[0] > 260 && tp_dev.x[0] < 390 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 260 && tp_dev.x[0] < 390 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i < 5) { password[i++] ='3'; } } else if (tp_dev.x[0] > 390 && tp_dev.x[0] < 520 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 390 && tp_dev.x[0] < 520 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i < 5) { password[i++] = '4'; } } else if (tp_dev.x[0] > 520 && tp_dev.x[0] < 650 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 520 && tp_dev.x[0] < 650 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i > 0) { password[--i] = '\0'; } } else if (tp_dev.x[0] > 650 && tp_dev.x[0] < 800 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) { while(tp_dev.x[0] > 650 && tp_dev.x[0] < 800 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480){ tp_dev.scan(0); } if (i == 4) { break; //退出密码输入循环 } else { Show_Hz16(300,250,"提示信息:用户名或密码错误",RED,WHITE); } } //显示部分 LCD_ShowString(400,150,400,24,24,password); } }
while (1) {
tp_dev.scan(0);
if (tp_dev.sta & TP_PRES_DOWN) { //触摸屏被按下
if (tp_dev.x[0] > 0 && tp_dev.x[0] < 130 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i < 5) {
password[i++] = '1';
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
} else if (tp_dev.x[0] > 130 && tp_dev.x[0] < 260 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i < 5) {
password[i++] = '2';
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
} else if (tp_dev.x[0] > 260 && tp_dev.x[0] < 390 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i < 5) {
password[i++] = '3';
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
} else if (tp_dev.x[0] > 390 && tp_dev.x[0] < 520 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i < 5) {
password[i++] = '4';
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
} else if (tp_dev.x[0] > 520 && tp_dev.x[0] < 650 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i > 0) {
password[--i] = '\0';
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
} else if (tp_dev.x[0] > 650 && tp_dev.x[0] < 800 && tp_dev.y[0] > 380 && tp_dev.y[0] < 480) {
if (i == 4) {
break; //退出密码输入循环
} else {
Show_Hz16(300,250,"提示信息:用户名或密码错误",RED,WHITE);
}
while(tp_dev.sta & TP_PRES_DOWN) { //等待触摸屏释放
tp_dev.scan(0);
}
}
//显示部分
LCD_ShowString(400,150,400,24,24,password);
}
}
在每个按键输入后,加入一个 while 循环等待触摸屏释放。这样可以防止连续点按导致密码输入错误。