include "../core/conf.php"; ### Check if env is set switch ($sitevar->env) { case "DEV": error_reporting(E_ALL); break; case "TEST": case "PROD": error_reporting(0); break; default: exit("no environment described - bye:)"); } ### test server connection and render frontpage if not logged in; include $sitevar->templatesPath . "header.php"; if ($sitevar->status == "up") { ### get frontpage include $sitevar->templatesPath . "main.php"; if (!empty($_SESSION["userdata"]["username"])) { echo "<a href='?logout=1'>logout</a>"; } #close connection; $dbc->close(); } else { array_push($sitevar->err, array("type" => "DB", "err" => "No connection was made.")); predump($sitevar->err); } include $sitevar->templatesPath . "footer.php"; ?>
/** * @param string $table * @param array $data * @param bool $onDuplicateUpdate (optional) * @return int */ public function insert($table, $data, $onDuplicateUpdate = false) { $multi = false; foreach ($data as $dk => $dv) { if (is_array($dv)) { $multi = true; } if (!$multi && is_numeric($dk) || $multi && is_numeric(array_keys($dv)[0])) { $this->triggerError("", array(), new \Exception("Passed in data array must be associative!")); return -1; } break; } if (!$multi) { $data = array($data); } $head = array_keys($data[0]); $count = count($data[0]); if ($count < 1) { $this->triggerError("", array(), new \Exception("Data array is empty")); return -1; } $place = ""; foreach ($data[0] as $v) { if ($this->isMS()) { if (!is_numeric($v)) { $place .= sprintf(",'%s'", $v); } else { $place .= sprintf(",%s", $v); } } else { $place .= ",?"; } } $place = ",(" . substr($place, 1) . ")"; $p = array(); $q = " INSERT INTO "; $q .= $this->prefixTable($table); $q .= ' ( '; $q .= implode(',', $head); $q .= ' ) VALUES '; if ($multi) { $q .= ' ( '; } $q .= substr(str_repeat($place, count($data)), 1); if ($multi) { $q .= ' ) '; } if ($onDuplicateUpdate) { $dup = ""; foreach ($head as $h) { $dup .= ",{$h}=VALUES({$h}) "; } $q .= " ON DUPLICATE KEY UPDATE " . substr($dup, 1); } if (!$this->isMS()) { foreach ($data as $dv) { foreach ($dv as $v) { $p[] = $v; } } } predump($q, $p); $this->execute($q, $p); return $this->isMS() ? false : intval($this->_pdo->lastInsertId()); }