public function write($line) { $options = $this->getOptions(); $keys = '"' . implode('","', array_map('trim', array_keys($line))) . '"'; // escaping values $values = array_map('XtoY\\Writer\\SQLWriter::escaping', array_values($line)); //imploding $values = '"' . implode('","', $values) . '"'; $sql = sprintf('INSERT INTO %s (%s) VALUES(%s)' . "\n", $options['table'], $keys, $values); fputs($this->document, $sql); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function write($line) { $translation = $this->document->createElement('trans-unit'); $translation->setAttribute('id', md5($line['source'])); $translation->setAttribute('resname', $line['source']); $s = $translation->appendChild($this->document->createElement('source')); $s->appendChild($this->document->createTextNode($line['source'])); $t = $translation->appendChild($this->document->createElement('target')); $t->appendChild($this->document->createTextNode($line['target'])); $this->body->appendChild($translation); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function write($line) { $options = $this->getOptions(); $keys = '' . implode(',', array_map('trim', array_keys($line))) . ''; $marks = implode(',', array_fill(0, count(array_keys($line)), '?')); $sql = sprintf('INSERT INTO %s (%s) VALUES(%s)' . "\n", $options['table'], $keys, $marks); $sth = $this->dbh->prepare($sql); try { $sth->execute(array_values($line)); } catch (\PDOException $e) { if (!$options['ignore_duplicate'] || $e->getCode() != 23000) { throw $e; } } if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }
public function write($line) { $options = $this->getOptions(); $cond = array(); foreach ($options['where'] as $f) { $cond[] = $f . '=' . $this->dbh->quote($line[$f]); unset($line[$f]); // if in where doesn't need to be updated } $fields = array(); foreach ($line as $k => $v) { $fields[] = $k . '=' . $this->dbh->quote($v); } $sql = sprintf('UPDATE %s SET %s WHERE %s' . "\n", $options['table'], implode(',', $fields), implode(' AND ', $cond)); $sth = $this->dbh->exec($sql); if ($this->reporter) { $this->reporter->setWrittenLines(++$this->line); } }