function dbsave() { $db = new ConexionBd(); if (!empty($this->id)) { $update = "UPDATE `" . $this->tabla . "` SET "; $arrayCampos = array(); foreach ($this->campos as $c => $nombre) { $arrayCampos[] = "`" . $c . "` = '" . $this->{$c} . "'"; } $update .= implode(', ', $arrayCampos); $update .= " WHERE id = '" . $this->id . "'"; $db->query($update); return $this->id; } else { $insert = "INSERT INTO `" . $this->tabla . "`\n\t\t\t\t\t\t\tVALUES("; $arrayCampos = array(); foreach ($this->campos as $c => $nombre) { if ($c != 'id') { $arrayCampos[] = "'" . $this->{$c} . "'"; } else { $arrayCampos[] = '0'; } } $insert .= implode(', ', $arrayCampos); $insert .= ");"; $db->query($insert); return $db->insertId(); } }
public static function getLinks($id = 0) { if (!isset($_SESSION)) { session_start(); } $db = new ConexionBd(); $sql = "SELECT *\n\t\t\t\t\tFROM links AS l\n\t\t\t\t\tLEFT JOIN user_link AS ul ON(l.id = ul.id_link)\n\t\t\t\t\tWHERE ul.id_user = " . $_SESSION['idusuario']; return $db->query($sql); }
public function getAccesos() { $sql = "SELECT * FROM clicks WHERE id_link = " . $this->id; $db = new ConexionBd(); return $db->query($sql, FALSE); }