Spade
Mini Shell
<?php
class db
{
public function __construct()
{
$servername = "138.201.86.61";
$username = "hanioir_fsharm";
$password = "j?sRP93MGS8P";
try {
$this->conn = new
PDO("mysql:host=$servername;dbname=hanioir_fsharm", $username,
$password);
// set the PDO error mode to exception
$this->conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$this->conn->exec("set names utf8mb4");
echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
public function query($sql, $type = 'r', $fetch =
'all', $data = null)
{
if ($type == 'r') {
$stmt = $this->conn->query($sql);
if ($fetch == 'all') {
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} elseif ($fetch == 'one') {
return $stmt->fetch(PDO::FETCH_ASSOC);
}
} elseif ($type == 'ioru') {
$sql = 'select id from users where chatid=' .
$data['chatid'];
$res = $this->query($sql, 'r', 'one');
if (empty($res)) {
$sql = "INSERT INTO users (" .
array_keys($data)[0] . "," . array_keys($data)[1] . ")
VALUES (?,?)";
$stmt = $this->conn->prepare($sql);
return $stmt->execute(array_values($data));
} else {
$sql = "UPDATE users SET " . array_keys($data)[1]
. "=? WHERE chatid=?";
$stmt = $this->conn->prepare($sql);
return $stmt->execute([array_values($data)[1],
array_values($data)[0]]);
}
}
}
}