Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('America/Sao_Paulo');
- class Connection
- {
- protected $mysqli;
- private const USER = 'root';
- private const PASS = '';
- private const HOST = 'localhost';
- private const DBNAME = 'painel';
- public function __construct()
- {
- $this->mysqli = new mysqli(self::HOST,self::USER,self::PASS,self::DBNAME);
- }
- public function select_by_email($email)
- {
- $query = $this->mysqli->query("SELECT * FROM `usuarios` WHERE `email` = '$email'");
- return $query->fetch_object();
- }
- public function select_by_username($username)
- {
- $query = $this->mysqli->query("SELECT * FROM `usuarios` WHERE `username` = '$username'");
- return $query->fetch_object();
- }
- public function select_by_id($id)
- {
- $query = $this->mysqli->query("SELECT * FROM `usuarios` WHERE `id` = '$id'");
- return $query->fetch_object();
- }
- public function update_credit($credit,$id)
- {
- $query = $this->mysqli->query("UPDATE `usuarios` SET `credit` = '$credit' WHERE `id` = '$id'");
- }
- public function select_all()
- {
- $query = $this->mysqli->query("SELECT * FROM `usuarios`");
- while ($row = $query->fetch_object()) {
- if ($row->status == 1) {
- $status = 'Ativo';
- }else {
- $status = 'Bloqueado';
- }
- echo "<tr>";
- echo "<td>".$row->username."</td>\n";
- echo "<td>".$row->email."</td>\n";
- echo "<td>".$row->credit."</td>\n";
- echo "<td>".$status."</td>\n";
- echo "<td>".date('d/m/Y H:i:s',$row->timeR)."</td>\n";
- echo "<td><a href='addcredit.php?id=".$row->id."' class='btn btn-success'>Adicionar créditos</a> <a href='delete.php?id=".$row->id."' class='btn btn-danger'>Excluir</a> <a href='block.php?id=".$row->id."' class='btn btn-warning'>Bloquear / Desbloquear</a></td>";
- echo "</tr>";
- }
- }
- public function delete_by_id($id)
- {
- $query = $this->mysqli->query("DELETE FROM `usuarios` WHERE `id` = '$id'");
- }
- public function update_status($status,$id)
- {
- $query = $this->mysqli->query("UPDATE `usuarios` SET `status` = '$status' WHERE `id` = '$id'");
- }
- }
Add Comment
Please, Sign In to add comment