-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.php
69 lines (56 loc) · 2.04 KB
/
engine.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/php
<?php
ini_set('default_charset','UTF-8');
$host = "127.0.0.1";
$user = "root";
$password = "";
$dbase = "database";
mysql_connect($host,$user,$password) or die ('Erro ao conectar na base de dados');
mysql_select_db($dbase);
$tables = array();
$result = mysql_query('SHOW TABLES');
$tables = array();
while($row = mysql_fetch_row($result)){
$tables[] = $row[0];
}
foreach ($tables as $key => $value) {
$primary = mysql_fetch_assoc(mysql_query("SHOW KEYS FROM ".$value." WHERE Key_name = 'PRIMARY'"));
update(select($value), $value, $primary['Column_name']);
}
function select($table){
$sql = "SELECT * FROM ".$table;
mysql_set_charset('latin1');
$result = mysql_query($sql);
$retorno = array();
while($row = mysql_fetch_assoc($result)){
$retorno[] = $row;
}
return $retorno;
}
function update($result, $table, $primary){
$update = 'UPDATE '.$table.' SET ';
foreach ($result as $value) {
foreach($value as $key=>$field){
if($primary == $key){
$where = ' WHERE '.$primary.' = '.$field;
} else {
$update .= $table.".".$key.' = ';
if(mb_detect_encoding($field, 'utf8, latin1') == 'ISO-8859-1' )
{
$update .= !is_numeric($field) ? "'".mysql_escape_string(utf8_encode($field))."', " : $field.', ';
} else {
$update .= !is_numeric($field)? "'".mysql_escape_string($field)."', " : $field.', ';
}
}
}
$update = substr($update,0,-2);
$update .= $where;
mysql_set_charset('utf8');
if(!mysql_query($update)){
die($update);
}
$update = 'UPDATE '.$table.' SET ';
$where = '';
}
}
?>