/** * Retrieves the name of the first primary key of a given table * @param string $table The table * @return string|null The primary key, or null if none exists */ private function getPrimaryKey($table) { if (empty($table)) { throw new \InvalidArgumentException('Invalid table name'); } $sql = "SHOW KEYS FROM `{$table}` WHERE Key_name = 'PRIMARY';"; $result = $this->db->query($sql)->fetch(); return $result ? $result['Column_name'] : null; }
/** * Writes event to database * @param array $data The event */ protected function doWrite(array $data) { if ($this->db === null) { throw new \RuntimeException('Database is null'); } if (empty($this->tableName)) { throw new \RuntimeException('Empty table name'); } $data = array_merge($data, $data['extra']); if ($data['ip']) { $data['ip'] = inet_pton($data['ip']); } $data['inserted_on'] = $data['timestamp']->format(DATETIME_MYSQL); if ($this->columnMap === null) { $this->db->insert($this->tableName, $data); } else { $data = $this->db->pick(array_keys($this->columnMap), $data); $this->db->insert($this->tableName, $this->mapEventIntoColumn($data, $this->columnMap)); } }
public function __construct($host, $user, $pass, $db) { parent::__construct(); $this->mysqli = new MySQLi($host, $user, $pass, $db); $this->mysqli->set_charset("utf8"); }