<strike>I need to import users to my WP database once a day.
So I have a script that runs once a day to do an action.
The problem that I'm having is that I'm a little over my head on this one.

Another company provides me with userdata in a .csv file.
I then need to import this file to my WP database.

The script I use for running once a day is the following (this is in my functions.php): 

    add_action( 'wp', 'prefix_setup_schedule' );
    /**
    * On an early action hook, check if the hook is scheduled - if not, schedule it.
    */
    function prefix_setup_schedule() {
	    if ( ! wp_next_scheduled( 'prefix_hourly_event' ) ) {
		    wp_schedule_event( time(), 'hourly', 'prefix_hourly_event');
	    }
    }


    add_action( 'prefix_hourly_event', 'prefix_do_this_hourly' );
    /**
    * On the scheduled action hook, run a function.
    */
    function prefix_do_this_hourly() {
	    wp_mail( '[email protected]', 'Automatic email sent at '.time(), 'Automatic scheduled email from WordPress.');
    }


On the server runs a cronjob that activates `wp-cron.php` once a day. If there aren't any users the script won't run so I activate it. Once there is activity it runs.
 
This is a simple working example of an email that is sent every hour.
Now I need to import users.

Here is what I found:

    LOAD DATA INFILE 'path/to/file/users.csv'
    INTO TABLE discounts
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    IGNORE 1 ROWS;

I don't know if this works I'm not there yet. The problem I'm facing now it that the usersystem of WordPres exists of two tables `wp_user` and `wp_usermeta`.

Can anybody tell me if I'm even on the right track and how to solve this. Is there maybe a way to seperate the .csv file and select what to import where including the fact that there is a refference between the `user` and `usermeta` tables?

M.</strike>

I changed my way of thinking and want to do the following:

    $row = 1;
	ini_set('auto_detect_line_endings',TRUE);
	if (($handle = fopen(get_bloginfo('template_directory')."/import_test.csv", "r")) !== FALSE) {
		while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
		$num = count($data);
		echo "<p> $num fields in line $row: <br /></p>\n";
		$row++;
		for ($c=0; $c < $num; $c++) {
			echo $data[$c] . "<br />\n";
		}
		}
		fclose($handle);
	}

This is a direct copy from http://php.net/fgetcsv. <br>
Now I want to replace the for loop with an `wp_create_user` function to add the user.<br>
At the same time I need to add user_meta to that user (I think).
Any ideas how I can add a user with metafields and select the right values from my csv file matching the `vars`?