1 | <?php |
---|
2 | //This script is to import the RMR data export from http://ccp.vo.llnwd.net/o2/data/data_misc_sql.rar into mySQL... enjoy |
---|
3 | // - Aaron Static - 20/10/2006 |
---|
4 | $db = mysql_connect("localhost","design","design") or die(mysql_error()); |
---|
5 | mysql_select_db("eve",$db) or die(mysql_error()); |
---|
6 | if ($dh = opendir("eve")) { |
---|
7 | while($file = readdir($dh)){ |
---|
8 | if(substr($file,strlen($file)-4,4) == ".sql"){ |
---|
9 | echo $file . "<br/>"; |
---|
10 | $sql = file_get_contents("eve/" . $file); |
---|
11 | $sql = str_replace("COMMIT;","",$sql); |
---|
12 | $sql = str_replace("';","');",$sql); |
---|
13 | $sql = str_replace(",true",",'true'",$sql); |
---|
14 | $sql = str_replace(",false",",'false'",$sql); |
---|
15 | $sql = str_replace("UNKNOWN","INTEGER",$sql); |
---|
16 | $sql = str_replace(",);",",NULL);",$sql); |
---|
17 | $sql = str_replace("CREATE TABLE","CREATE TABLE IF NOT EXISTS",$sql); |
---|
18 | $sql = str_replace(",,,,",",NULL,NULL,NULL,",$sql); |
---|
19 | $sql = str_replace(",,,",",NULL,NULL,",$sql); |
---|
20 | $sql = str_replace(",,",",NULL,",$sql); |
---|
21 | $sql = str_replace("dbo.","",$sql); |
---|
22 | $s = explode(";\r",$sql); |
---|
23 | foreach($s as $query){ |
---|
24 | set_time_limit(90); |
---|
25 | //echo $query; |
---|
26 | if(trim($query) != ""){ |
---|
27 | if(preg_match_all("/ CHAR\\((.*?)\\)/",$query,$matches,PREG_SET_ORDER)){ |
---|
28 | foreach($matches as $match){ |
---|
29 | echo $match[0] . "/"; |
---|
30 | if($match[1] > 255){ |
---|
31 | $query = str_replace($match[0],"TEXT",$query); |
---|
32 | }else{ |
---|
33 | $query = str_replace($match[0],"VARCHAR({$match[1]})",$query); |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|
37 | //echo "'$query'<br/>"; |
---|
38 | mysql_query($query,$db) or die("<hr/><b>" . mysql_error() . "<Br/><br/>$query" . "</b>"); |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | } |
---|
43 | closedir($dh); |
---|
44 | } |
---|
45 | ?> |
---|