/** * Prepare statement * @param string $TableName * @param array $Columns * @param int $accountID */ protected function prepareStatement($TableName, array $Columns, $accountID) { $TableName = str_replace('runalyze_', PREFIX, $TableName); $PreparedColumns = '`' . implode('`,`', $Columns) . '`'; $PreparedValues = implode(',', array_fill(0, count($Columns), '?')); if ($accountID !== false && $TableName != PREFIX . 'equipment_sport' && $TableName != PREFIX . 'activity_equipment' && $TableName != PREFIX . 'activity_tag') { $PreparedColumns .= ',`accountid`'; $PreparedValues .= ',' . $accountID; } $this->Statement = $this->DB->prepare('INSERT INTO `' . $TableName . '` (' . $PreparedColumns . ') VALUES (' . $PreparedValues . ')'); }
/** * @covers PDOforRunalyze::prepare */ public function testPrepare() { $Insert = $this->object->prepare('INSERT INTO `runalyze_training` (`id`, `s`, `distance`, `accountid`) VALUES (:id, :s, :distance, 0)'); $Insert->bindValue('id', 1); $Insert->bindValue('s', 300); $Insert->bindValue('distance', 1); $Insert->execute(); $Insert->bindValue('id', 2); $Insert->bindValue('s', 610); $Insert->bindValue('distance', 2.1); $Insert->execute(); $Insert->bindValue('id', 3); $Insert->bindValue('s', 3111); $Insert->bindValue('distance', 11.23); $Insert->execute(); $id = 0; $RequestDistance = $this->object->prepare('SELECT `distance` FROM `runalyze_training` WHERE `id`=:id'); $RequestDistance->bindParam('id', $id); $id = 1; $RequestDistance->execute(); $this->assertEquals(1, $RequestDistance->fetchColumn()); $id = 2; $RequestDistance->execute(); $this->assertEquals(2.1, $RequestDistance->fetchColumn()); $id = 3; $RequestDistance->execute(); $this->assertEquals(11.23, $RequestDistance->fetchColumn()); $this->object->exec('TRUNCATE TABLE `runalyze_training`'); }
/** * Prepare update statement * @param string $TableName * @return PDOStatement */ private function prepareUpdateStatement($TableName) { switch ($TableName) { case 'runalyze_conf': return $this->DB->prepare('UPDATE `' . PREFIX . 'conf` SET `value`=? WHERE `accountid`=' . $this->AccountID . ' AND `key`=?'); case 'runalyze_dataset': return $this->DB->prepare(' UPDATE `' . PREFIX . 'dataset` SET `active`=?, `style`=?, `position`=? WHERE `accountid`=' . $this->AccountID . ' AND `keyid`=?'); case 'runalyze_plugin': return $this->DB->prepare('UPDATE `' . PREFIX . 'plugin` SET `active`=?, `order`=? WHERE `accountid`=' . $this->AccountID . ' AND `key`=?'); case 'runalyze_plugin_conf': return $this->DB->prepare('UPDATE `' . PREFIX . 'plugin_conf` SET `value`=? WHERE `pluginid`=? AND `config`=?'); } }