menus
This commit is contained in:
+26
-7
@@ -40,22 +40,36 @@ class Database {
|
||||
public function query($sql, $params = []) {
|
||||
try {
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
if (!empty($params)) {
|
||||
$stmt->execute($params);
|
||||
} else {
|
||||
$stmt->execute();
|
||||
}
|
||||
return $stmt;
|
||||
} catch (PDOException $e) {
|
||||
error_log("Query failed: " . $e->getMessage() . " SQL: " . $sql);
|
||||
throw new Exception("Error en la consulta a la base de datos");
|
||||
error_log("Query failed: " . $e->getMessage() . " SQL: " . $sql . " Params: " . json_encode($params));
|
||||
throw new Exception("Error en la consulta a la base de datos: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch($sql, $params = []) {
|
||||
$stmt = $this->query($sql, $params);
|
||||
return $stmt->fetch();
|
||||
try {
|
||||
$stmt = $this->query($sql, $params);
|
||||
return $stmt->fetch();
|
||||
} catch (Exception $e) {
|
||||
error_log("Fetch failed: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function fetchAll($sql, $params = []) {
|
||||
$stmt = $this->query($sql, $params);
|
||||
return $stmt->fetchAll();
|
||||
try {
|
||||
$stmt = $this->query($sql, $params);
|
||||
return $stmt->fetchAll();
|
||||
} catch (Exception $e) {
|
||||
error_log("FetchAll failed: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function insert($table, $data) {
|
||||
@@ -99,6 +113,11 @@ class Database {
|
||||
return $this->pdo->rollback();
|
||||
}
|
||||
|
||||
public function execute($sql, $params = []) {
|
||||
$stmt = $this->query($sql, $params);
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
public function lastInsertId() {
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user