示例#1
0
# @see http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html
$mdb->loadModule('Manager');
// Extended, Datatype, Manager, Reverse, Native, Function
# get all the field names
$table_field_names = $mdb->listTableFields($table_name);
$nfields = count($table_field_names);
# need to issue a query against the desired table to get the metadata
$query = "SELECT * FROM {$table_name}";
# on success this returns an MDB2_Result handle
# TODO - deal with the failure condition here
#$result = $mdb->query($query, true, true, 'MDB2_BufferedIterator');
$result =& $mdb->query($query, true, true);
# now that we have a result set, we can get the field types
# as an array:
$dt = new DatabaseTable();
$dt->set_raw_table_name($table_name);
$dt->set_raw_field_names($table_field_names);
$dt->set_db_field_types($result->types);
# assign all the smarty variables
$smarty->assign('classname', $dt->get_camelcase_table_name());
$smarty->assign('objectname', $dt->get_java_object_name());
$smarty->assign('tablename', $table_name);
$smarty->assign('fields', $dt->get_camelcase_field_names());
$smarty->assign('fields_as_insert_csv_string', $dt->get_fields_as_insert_stmt_csv_list());
$smarty->assign('prep_stmt_as_insert_csv_string', $dt->get_prep_stmt_insert_csv_string());
$smarty->assign('prep_stmt_as_update_csv_string', $dt->get_fields_as_update_stmt_csv_list());
$smarty->assign('types', $dt->get_java_field_types());
$smarty->assign('dt', $dt);
# TODO - this is hard-coded
$out = $smarty->fetch("{$template}.tpl");
echo $out;