diff --git a/sampleConfig.xml b/sampleConfig.xml index 3f5ea28..da480da 100644 --- a/sampleConfig.xml +++ b/sampleConfig.xml @@ -9,4 +9,5 @@ + diff --git a/src/CreepyCoder.php b/src/CreepyCoder.php index eb1e8ec..d8c7c90 100644 --- a/src/CreepyCoder.php +++ b/src/CreepyCoder.php @@ -98,3 +98,12 @@ } } +$configList = $xmlDoc->getElementsByTagName('WriteDB'); +$configListLength = $configList->length; +if ($configListLength > 0) { + require dirname(__FILE__).DIRECTORY_SEPARATOR.'WriteDB.php'; + for($pos=0; $pos<$configListLength; $pos++) { + $dataManager->writeData(new WriteDB($configList->item($pos))); + } +} + diff --git a/src/WriteDB.php b/src/WriteDB.php new file mode 100644 index 0000000..ef4f0ef --- /dev/null +++ b/src/WriteDB.php @@ -0,0 +1,56 @@ +. +**/ + + +class WriteDB extends BaseWriteClass { + + + protected $dsn; + protected $userName = "cc"; + protected $password = "cc"; + protected $tableName = "data"; + protected $timeFieldName = "data"; + + + public function __construct($configData = array()) { + if (get_class($configData) == 'DOMElement') { + $this->dsn = $configData->getAttribute('DSN'); + // TODO: Only + if ($configData->hasAttribute('UserName')) $this->userName = $configData->getAttribute('UserName'); + if ($configData->hasAttribute('Password')) $this->password = $configData->getAttribute('Password'); + if ($configData->hasAttribute('TableName')) $this->tableName = $configData->getAttribute('TableName'); + if ($configData->hasAttribute('TimeFieldName')) $this->timeFieldName = $configData->getAttribute('TimeFieldName'); + } + parent::__construct($configData); + } + + public function write() { + + $pdo = new PDO($this->dsn, $this->userName, $this->password); + + $stat = $pdo->prepare("INSERT INTO ".$this->tableName." SET ".$this->timeFieldName."=:d"); + + foreach($this->dataManager->getData() as $item) { + $stat->bindValue('d', $item->getDateTimeAs('Y-m-d H:i:s'), PDO::PARAM_STR); + $stat->execute(); + } + + } + +} +