By the way that code is not exact so don't bother picking out little errors in code as its just a kind of snapshot of what I've been doing.... no matter what I do the general errors I get remain, even in other scripts.
some notes:
The import scripts from wenyue did not read the DB settings from override files like settings/override/site.ini.append.
It only checked for the DB settings in settings/site.ini. I didn't read your code now, but can you check, if your (source) data is read currectly from your source-DB?
About the errors: "Call to member function on a non object", "invalid argument supplied to foreach()", you should read my comment and/or forum thread, IF you are importing to a non-english-DB: http://ez.no/developer/ez_publish_3/contributions/import_script_for_data_import_from_22_to_3x#msg35392