/** * [execute description]. * * @param mixed $mode kjshdfjkshdf * sdfsdfsdfsdfsdf * @param [type] $args [description] * * @return [type] [description] */ public function execute($mode = null, $args = null) { switch ($this->queryType) { case self::SELECT: case self::ROW: case self::SINGLE: $this->stmt->execute(); if ($mode === 'object') { $this->stmt->setFetchMode(\PDO::FETCH_OBJ); } elseif (is_object($mode)) { $this->stmt->setFetchMode(\PDO::FETCH_INTO, $mode); } elseif ($mode === 'array' || $mode === null) { $this->stmt->setFetchMode(\PDO::FETCH_ASSOC); } else { $this->stmt->setFetchMode(\PDO::FETCH_CLASS, $mode, $args); } break; case self::COLUMN: $this->stmt->execute(); break; case self::INSERTINTO: $this->sql .= ' (' . implode(',', $this->cols) . ') VALUES '; $cols = []; $data = []; $update = []; foreach ($this->data as $n => $col) { foreach ($this->cols as $k => $v) { $data['param' . $n . $k] = isset($col[$v]) ? $col[$v] : ($col[$v] === NULL ? NULL : ''); $cols[$n][] = ':param' . $n . $k; if ($this->updateOnDuplicate && !isset($update[$v])) { $update[$v] = $v . ' = VALUES(' . $v . ')'; } } $cols[$n] = '(' . implode(', ', $cols[$n]) . ')'; } $this->sql .= implode(', ', $cols); if ($this->updateOnDuplicate) { $this->sql .= ' ON DUPLICATE KEY UPDATE ' . implode(', ', $update); } $this->stmt = MysqlConnection::prepare($this->sql); $this->bindParams($data); case self::INSERT: case self::UPDATE: case self::DELETE: $this->resetVars(); $results = $this->stmt->execute() == true ? $this->stmt->rowCount() : false; $this->insertID = MysqlConnection::lastInsertId(); break; case self::QUERY: $this->resetVars(); $results = $this->stmt->execute(); $this->insertID = MysqlConnection::lastInsertId(); break; } if ($this->queryType === self::SELECT) { $results = $this->stmt->fetchAll(); } elseif ($this->queryType === self::COLUMN) { $results = $this->stmt->fetchAll(\PDO::FETCH_COLUMN); } elseif ($this->queryType === self::SINGLE) { $results = $this->stmt->fetchColumn(); } elseif ($this->queryType === self::ROW) { $results = $this->stmt->fetch(); } $this->resetVars(); $this->rowCount = $this->stmt->rowCount(); $this->columnCount = $this->stmt->columnCount(); $this->stmt->closeCursor(); return $results; }