很easy的,你update
'DBname'
'num'='?'
就可以了.
DBname填数据库名,?填修改后的值.
另一个思路你试试:
html:
input?type="text"?name="A[]"?/
input?type="text"?name="B[]"?/
input?type="hidden"?name="ids[]"?value="{$id}"?/
php:
php
$a?=?$_POST['A'];
$b?=?$_POST['B'];
$ids?=?$_POST['ids'];
foreach($a?as?$k?=?$v)?{
$sql?=?"update?abc?set?a='{$v}',?b='{$b[$k]}'?where?id='{$ids[$k]}'";
mysql_query($sql);
}
Binlog 由事件(event)组成,请注意是事件(event)不是事务(transaction),一个事务可以包含多个事件.事件描述对数据库的修改内容.
找出 Binlog 中的大事务
切割 Binlog 中的大事务
了解了 Binlog 的结构,再加上 Python 这把瑞士军刀,我们还可以实现很多功能,例如我们可以统计哪个表被修改地最多?我们还可以把 Binlog 切割成一段一段的,然后再重组,可以灵活地进行 MySQL 数据库的修改和迁移等工作.
很easy的,你update 'DBname' 'num'='?' 就可以了. DBname填数据库名,?填修改后的值.
举例如下:
创建userinfo_update.php页面用于查询用户信息,先显示信息,在修改:
先通过GET获取用户编号查询用户信息:
$sql = "select * from user_info where user_id='".$_GET['userId']."'";
$result = mysql_query($sql,$con);
if($row = mysql_fetch_array($result)){
页面效果:
创建update.php文件,用于修改用户信息:
使用到了mysql_affected_rows() 函数返回前一次 MySQL 操作所影响的记录行数.
//通过post获取页面提交数据信息
$userId = $_POST[userId];
$userName = $_POST[userName];
$userAge = $_POST[userAge];
$sql = "update user_info set user_name='".$userName."',user_age=".$userAge." where user_id='".$userId."'";
mysql_query($sql,$conn);//执行SQL
$mark? = mysql_affected_rows();//返回影响行数
$url = "userinf_select.php";
运行结果
创建delete.php文件,完成删除用户信息功能:
$userId = $_GET['userId'];
include 'connection.php';
$sql = "delete from user_info where user_id='".$userId."'";
mysql_query($sql,$con);
if($mark0){
echo "删除成功";
}else{
echo? "删除失败";
mysql_close($con);
运行结果:
function updatecols($table,$arr){
$sql = "update ".$table." set ";
$total = count($arr);
$i=1;
foreach($arr as $k=$v){
$sql .= $k."=".$v;
if($i$total){
$sql .= ",";
$i++;
return $sql;
以上就是土嘎嘎小编为大家整理的php如何批量修改数据库相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!