Mysql 在数据库中的表之间替换列值
我的数据库中有两个表,在不同表的不同列中有一个公共值。我想用数据库中所有表中的新值替换该值 例如: tbl1:Mysql 在数据库中的表之间替换列值,mysql,Mysql,我的数据库中有两个表,在不同表的不同列中有一个公共值。我想用数据库中所有表中的新值替换该值 例如: tbl1: id gid pid 1 local new 2 remote old 3 local local 4 remote new id gid pid 1 local new 2 new old 3 local
id gid pid
1 local new
2 remote old
3 local local
4 remote new
id gid pid
1 local new
2 new old
3 local local
4 remote local
tbl2:
id gid pid
1 local new
2 remote old
3 local local
4 remote new
id gid pid
1 local new
2 new old
3 local local
4 remote local
我想在数据库中的所有表标签中用IP
10.0.0.0
替换“local”单词。您可以使用php和mysql,如下所示
<?php
$db = mysql_connect(‘localhost’,’myuser_mydbuser‘,’mypassword‘);
if(!$db) echo "Cannot connect to the database – incorrect details";
mysql_select_db(‘myuser_mydbname’);
$result=mysql_query(‘show tables’);
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("UPDATE $value set pid = '10.0.0.0' WHERE pid = 'local' ");
}}
echo "The collation of your database has been successfully changed!";
?>