Problem
I'm trying to create multiple nodes at once using a CSV file for the data. However my script only creates the first 25 before it throws the following error. Any ideas what might be happening?
PDOException: in drupal_write_record() (line 7166 of C:\XAMPP\htdocs\drupalie\includes\common.inc).
Set-Up
I have a custom form which creates the nodes on submit. The form just has a submit button.
This is the submit handler. I only have one column in my CSV sheet so I don't actually use the delimiter. First I generate an array with each node name.
if (($handle = fopen("sites/all/modules/custom/generatenodes/nodes_database_import.csv", "r")) !== FALSE) {
//open the CSV file
$length = 1000;
$delimiter = "|";
//set the length and delimiter.
while (!feof($handle)) {
//$line is an array of the csv elements
$node_name_array[] = fgetcsv($handle, $length, $delimiter);
}
fclose($handle);
}
The array looks like this:
I then create the nodes:
global $user;
foreach ($node_name_array as $nodename) {
if($nodename == FALSE) {
return;
}
$values = array(
'type' => 'school',
'uid' => $user->uid,
'status' => 1,
'comment' => 0,
'promote' => 0,
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->title->set($nodename['0']);
$ewrapper->field_country->set($schoolname['0']);
$ewrapper->save(true);
entity_save('node', $entity);
}
But it breaks after the first 25 or so. What have I missed?
EDIT--
So I found the cause. It's to do with the values in my CSV file. Sometimes it likes them othertimes it doesn't. If I replace these values then it works up to the next broken value.
The first problem was a value with an accented e inside. Removing the accent fixed it.
Unfortunately the next two which broke it are not so obvious:
- Putian Cambridge English
- Zhangzhou Bilingual Middle School
Yet the following values work:
- Quanzhou Foreign Language Middle School
- International College of Xiamen University
I've only pasted in clean values, but something is breaking it. Any ideas?
Trying to navigate to the content page after causes MySQL to break. Here's the error log:
https://www.dropbox.com/s/jji3cw559filq03/mysqlcrash_log.txt