|
1:
<?php 2: #################################################################### 3: # # 4: # PHP dbfConverter V0.9 # 5: # import data from dbase format to mysql or postgres # 6: # by kroket Jun.2002 kroket@bo-bo.si # 7: # http://server.bo-bo.si/php/dbfConverter/ # 8: # # 9: #################################################################### 10: # 11: # V0.9 (01.07.2002) 12: # Fixed simple bug for inserting field 'Units' 13: # Added support for conversion to PostgreSQL 14: # 15: # V0.8 (24.04.2002) 16: # Added all possible field types for xBase table files and 17: # memo files. I tested this script only with clipper dbf's and dbt's, 18: # but i think this script should also work with other databases 19: # (foxpro dbf's and fpt's). 20: # 21: # V0.7 (17.04.2002) 22: # Added support for memo files (dbt). Simply just copy dbt 23: # files in directory. Script reads it automaticaly. 24: # 25: # V0.6 (14.04.2002) 26: # Script now read data direct from file, we can now use it without 27: # --enable-dbase option (added in V0.6) 28: # 29: #################################################################### 30: # 31: # 32: # 33: # 34: # Default in PHP is 30sec for execute the script. 35: # We need more time 36: $maxExecTime="0"; 37: # 38: $Title_name="dbfConverter"; 39: # 40: # units, if we have more then one dbf files with same name. 41: # for every $unit[..]="name" we must create directory "name" & 42: # put dbf files in that directory. 43: # In mysql database we get dirname_dbffilename table 44: # 45: # example: i have 2 video rentals with same dbf files in 2 cities. 46: # One city is Vrhnika, second city is Grosuplje. I make directory 47: # vrhnika & put in movies.dbf file from video-vrhnika & i make another 48: # directoey grosuplje & put in movies.dbf file from video-grosuplje 49: # In mysql database i get 2tables: vrhnika_movies & grosuplje_movies 50: # 51: # we can make unlimit number of units 52: # 53: $unit[1]="vrhnika"; 54: $unit[2]="grosuplje"; 55: $unit[3]="blabla"; 56: # 57: # where do we connect to mysql server 58: # 59: $sql_host="localhost"; 60: # 61: # mysql username 62: # 63: $sql_user=""; 64: # 65: # mysql password 66: # 67: $sql_pass=""; 68: # 69: # mysql database name 70: # 71: $sql_db=""; 72: # 73: # which database server we will use 74: # MySQL or PostgreSQL 75: # !! case sensitive !! 76: //$sql_type="PostgreSQL"; 77: $sql_type="MySQL"; 78: # 79: # This is characters or words which you like to transform data from dbf 80: # files. 81: # 82: $transform["^"]="È"; # this lines down is for transform 852charset 83: $transform["@"]="Ž"; # to windows1250 (slovenian ;-) 84: $transform["["]="Š"; # here you can putt entire word 85: $transform["{"]="š"; # or here 86: $transform["`"]="ž"; # or here 87: $transform["~"]="è"; # & you can write more $transforms[] 88: $transform["hacker"]="cracker";# ;-) 89: # 90: # We can put 2 or more dbf files in one mysql table 91: # example: we have movies.dbf from directory vrhnika & movies.dbf 92: # from directory grosuplje. As jousual we got vrhnika_movies & 93: # grosuplje_movies. Here we can setup for both mysql tables to 94: # go in the same table named movies_all. Ofcourse databases must 95: # have same field names & types. 96: # 97: $transformTableNames["vrhnika_movies"]="movies_all"; 98: $transformTableNames["grosuplje_movies"]="movies_all"; 99: # 100: # or just change the name of mysql table for blabla_movies 101: # 102: $transformTableNames["blabla_movies"]="i_dont_like_that_table_name"; 103: # 104: # If we group 2 or more dbf files in one mysql table, we need the new 105: # field called 'unit' or whatever. in this field will be stored string 106: # from wich unit(directory) is this row. Default is without this. 107: # If you enable this option, unit (directory) names must be less 108: # than 16 characters!!! 109: # 110: $needUnitName["movies_all"]=1; 111: # 112: # rename mysql Field for units however you want ;-) 113: $fieldUnitName="Unit"; 114: # 115: # On default all databases not have primary key id field. Here we can got them. 116: $needID["i_dont_like_that_table_name"]=1; 117: $needID["blabla_lala"]=1; 118: # 119: # If we doing this first time, mysql tables will be created, if we updating 120: # existing mysql tables, we can update on a few ways: 121: # 122: # $updateMode[]=1 Delete all data in table & insert new data from file. 123: # If we have defined Field 'Unit' (when we have more then one 124: # dbfs in table), this seting delete only data from this unit. 125: # example: if you updating only vrhnika in movies_all, all data 126: # from database which contains Unit="VRHNIKA" will be deleted & new 127: # data from vrhnika will be inserted. In this case we can't set 128: # ID fields, becouse ID will grow for every update! 129: # 130: # $updateMode[]=2 Insert only newer rows. Preety good if you just add new records 131: # in the database in your dos program! This is much faster, becouse 132: # we insert only newer records from dbf file. 133: # default is 1 134: # 135: $updateMode["movies_all"]=1; 136: $updateMode["i_dont_like_that_table_name"]=2; 137: # 138: # we can make some conditions whitch data will be deleted from mysql table 139: # if we have some data in dbf whitch we dont wont in mysql. 140: # Stupid way, i know, but if we want this in config file... 141: # syntax is $data_delete["mysql_table_name"]="Field_name operator value"; 142: # we can write anything which in mysql query come after WHERE! 143: # example: $data_delete["movies_all"]="`St_kasete`>11 AND `St_kasete`<1500 AND (`Tema`='PORNO' OR `Tema`='AKC.')"; 144: # 145: $data_delete["movies_all"]="`St_kasete` <= 11"; 146:
|