import_xls.pl

Task: import excel file, containing information about the project into the database. File has 2 worksheets:
  1. words
  2. project
At first we parse

project worksheet

project google_domains
pages_to_check$pages_to_check languagede
pages_to_save$pages_to_savecountry_codede
competitor_benchmark150domainhttp://google.de/search?q=%word%&pws=0
domaindomain.de
project worksheet
The first row contains the names of the tables. Every other row contains column name and value for each table. These values must be inserted into the

database tables

project
id domain pages_to_check pages_to_save competitor_benchmark
$project_id domain.de $pages_to_check $pages_to_save 150
google_domains
id domain language country_code
$google_domains_id http://google.de/search?q=%word%&pws=0 de de

$project_id and $google_domains_id are automatically generated by MySQL and will be used later.

words worksheet

When we have the same word, belonging to the different group, it must only be added to words_in_group table, if it's missing there. Here the word 1_1 encounters in 2 rows with the same data, except for the group.

KEY GLO LOC CPC GROUP
1_1 1_2 1_3 1_4 1_5
1_1 1_2 1_3 1_4 2_5
words worksheet

database tables

words
id word
$word_id 1_1
words_groups
id name
$group_id1 1_5
$group_id2 2_5
words_in_group
group_id word_id
$group_id1 1_5
$group_id2 1_5
project_words_domains
project_id domain_id word_id global_monthly_search local_monthly_search CPC
$project_id $google_domains_id $word_id 1_2 1_3 1_4
Attaching words to the project and google domain, using project_words_domains table

$word_id, $group_id1, $group_id2 are generated automatically

Functions

  1. import_excel
    1. parse_header
    2. read_row
    3. get_group_id
    4. parse_domain_worksheet
    5. check_word
    6. add_to_words
    7. add_words_in_group
    8. insert_into_table