| Server IP : 95.46.96.79 / Your IP : 216.73.216.4 Web Server : Apache/2.4.41 (Ubuntu) System : Linux zaimer.uz 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : akslabs_uz_usr ( 1001) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/sugurtatrip__usr95/data/www/sugurtatrip.uz/apiv1/user/database/ |
Upload File : |
<?php
class Database {
private $connection;
public function __construct()
{
$this->connection = new \mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASS'], $_ENV['DB_NAME']);
if ($this->connection->connect_error) {
die("Connection failed: " . $this->connection->connect_error);
}
}
public function query($sql)
{
$result = $this->connection->query($sql);
if ($result === FALSE) {
Logger::log($this->connection->error, 'error');
return false;
}
return $result;
}
public function prepare($sql)
{
$stmt = $this->connection->prepare($sql);
if (!$stmt) {
Logger::log("Prepare failed: " . $this->connection->error, 'error');
return false;
}
return $stmt;
}
public function escapeString($string)
{
return $this->connection->real_escape_string(trim($string));
}
public function addUserAndGetId($input)
{
$query = "INSERT INTO clients (
first_name,
second_name,
passport_series,
passport_number,
birth_date,
client_phone
) VALUES (
'{$input['firstName']}',
'{$input['secondName']}',
'{$input['passportSeries']}',
'{$input['passportNumber']}',
'{$input['birthDate']}',
'{$input['clientPhone']}'
)";
if ($this->connection->query($query) === TRUE) {
return $this->connection->insert_id;
} else {
Logger::log("Error: " . $query . "<br>" . $this->connection->error, 'error');
return false;
}
}
public function addConfirmationCode($user_id, $code) {
$message_id = uniqid($user_id."_");
$utcTimezone = new \DateTimeZone('UTC');
$utcNow = new \DateTime('now', $utcTimezone);
$created_at = $utcNow->format('Y-m-d H:i:s');
$query = "INSERT INTO sended_codes (
message_id,
client_id,
confirmation_code,
confirmed,
created_at,
confirmed_at) VALUES (
'$message_id',
$user_id,
$code,
0,
'$created_at',
'NULL'
)";
if ($this->connection->query($query) === TRUE) {
return $this->connection->insert_id;
} else {
Logger::log("Error: " . $query . "<br>" . $this->connection->error, 'error');
return false;
}
}
public function close()
{
$this->connection->close();
}
}