/** * Tests PDO instance with silent errors. First inert prepares the statement, second creates an exception. * * @expectedException \Ddeboer\DataImport\Exception\WriterException */ public function testWriteFailureWithNoException() { $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); $writer = new PdoWriter($this->pdo, 'example'); $writer->prepare(); $writer->writeItem(array('foo', 'bar')); $writer->writeItem(array('foo', 'bar', 'baz')); $writer->finish(); }
/** * DbWriter constructor. * @param Configuration $config */ public function __construct(Configuration $config) { $host = $config->get(array('host'), 'localhost'); $dbname = $config->get(array('dbname'), ''); $dbtype = $config->get(array('dbtype'), 'mysql'); $username = $config->get(array('username'), 'root'); $password = $config->get(array('password'), ''); $table = $config->get(array('table'), ''); $charset = $config->get(array('charset'), 'utf8'); // Array containing fields that need to be checked to avoid duplicate data $this->uniqueFields = $config->get(array('unique'), array()); // Create PDO object from config $pdo = new \PDO($dbtype . ':host=' . $host . ';dbname=' . $dbname . ';charset=' . $charset, $username, $password); // Set PDO error modes (for error output) $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); parent::__construct($pdo, $table); }