function mymodule_import() {
// get the old data
$old_db = mysql_connect("host", "user", "pass") or die('Could not connect to mysql server.' );
mysql_select_db('old_db', $old_db) or die('Could not select database.');
$sql = "select * from old_table";
$result = mysql_query($sql, $old_db);
while ($row = mysql_fetch_object($result)) {
$data[] = $row;
}
// till this is working, only do it with one row
$row = $data[0];
$form_state = array();
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'property');
// array of values based on mapping between old & new dbs
$form_state['values']['field_id'][0]["value"] = $row->UniqueID;
$form_state['values']['field_block'][0]["value"] = $row->Block;
$form_state['values']['field_lot'][0]["value"] = $row->Lot;
$form_state['values']['field_zoning'][0]["value"] = $row->Zoning;
$form_state['values']['field_description'][0]["value"] = $row->Comment;
$form_state['values']['field_annual_tax'][0]["value"] = nums_only($row->Taxes);
$form_state['values']['field_tax_land'][0]["value"] = nums_only($row->Land_Assessment);
$form_state['values']['field_tax_improvements'][0]["value"] = nums_only($row->Improvement_Assesment);
$form_state['values']['field_address1'][0]["value"] = $row->Addr1;
$form_state['values']['field_address2'][0]["value"] = $row->Addr2;
$form_state['values']['field_city'][0]["value"] = $row->City;
$form_state['values']['field_state'][0]["value"] = $row->State;
$form_state['values']['field_zip'][0]["value"] = $row->Zip;
// node meta data
$form_state['values']['status'] = 1;
$form_state['values']['name'] = 'Joe Manager';
/*
these fields may be buggy because they're tricky or not in old db
# Region
# Type
# Use
# Building Size
# Land Area
# Land Unit
# Price
# Price Type
# Commission
# Commission Type
# From date
# Owner
*/
$form_state['values']['field_region'][0]["value"] = "Eastern Region";
$form_state['values']['field_type'][0]["value"] = $row->Proptype;
$form_state['values']['field_use'][0]["value"] = $row->Proptype;
$form_state['values']['field_building_size'][0]["value"] = nums_only($row->Building_Size);
$form_state['values']['field_land_area'][0]["value"] = nums_only($row->Land_Size);
$form_state['values']['field_land_unit'][0]["value"] = "acres";
$form_state['values']['field_land_area'][0]["value"] = nums_only($row->Land_Size);
$form_state['values']['field_price'][0]["value"] = nums_only($row->Price);
$form_state['values']['field_price_type'][0]["value"] = "gross";
$form_state['values']['field_commission'][0]["value"] = 1;
$form_state['values']['field_commission_type'][0]["value"] = "%";
$form_state['values']['field_owner'][0]["uid"] = "11";
// this one should mostly work, but there may be some problems
$form_state['values']['field_contract_type'][0]["value"] = "For " . $row->PriceType;
drupal_execute('property_node_form', $form_state, (object)$node);
$msg = "wrote property " . $row->UniqueID . " (or tried to, anyway)";
drupal_set_message($msg);
drupal_goto('properties');
}
function nums_only($str) {
return preg_replace("/[^0-9]/", "", $str);
}