setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo 'Created/opened the database'; echo "\r\n"; } catch(PDOException $e) { echo $e->getMessage(); exit(0); } $pattern = "/^\s*([^,]+),\s+(.+)$/"; $words = array("hello, hola","science, ciencia"); //////////////////////////////////////////////////////////////////////// foreach ($words as $key => $value) { print $key . " => " . $value . "\n"; if (preg_match($pattern, $value, $matches)){ for ($i = 1; $i < count($matches); $i++) { print $matches[$i] . "|"; } print "\n"; if ( isset($db) && count($matches) == 3 ) { $en = $db->quote($matches[1]); $sp = $db->quote($matches[2]); if ($db->query('INSERT INTO english (lexeme) VALUES (' . "$en)") ) { print "inserted $en into english" . "\n"; $id_en = $db->lastInsertID(); print "row id is $id_en\n"; } else { print "couldn't insert $en into english" . "\n"; } if ($db->query('INSERT INTO spanish (lexeme) VALUES (' . "$sp)") ) { print "inserted $sp into spanish" . "\n"; $id_sp = $db->lastInsertID(); print "row id is $id_sp\n"; } else { print "couldn't insert $sp into spanish" . "\n"; } if ( isset($id_en) && isset($id_sp) ) { if ($db->query('INSERT INTO translate (en, sp) VALUES (' . "$id_en, $id_sp)") ) { print "inserted $id_en, $id_sp into translate" . "\n"; } else { print "couldn't insert $id_en, $id_sp into translate" . "\n"; } } else { print "couldn't insert into translate" . "\n"; } } else if ( !isset($db) ) { print "db $file is not set\n"; } else { print "incorrect number of matches\n"; } }else{ echo 'ERROR: could not use pattern/value/match sequence'; echo "\r\n"; } } ?>