Add Captcha model in database_connrction.php
Write the generate random Database Connection in DBConnectionService.php database class
require_once("Logs.php");
require_once("UtilityService.php");
defined('env') or define("env", "LOCAL");
if (env == "LOCAL") {
define("HOST", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DBNAME", "trulloy_management");
} else if (env == "PROD") {
define("HOST", "localhost");
define("USERNAME", "tr_super_user");
define("PASSWORD", "trulloy@2024");
define("DBNAME", "trulloy_management");
}
class DBConnectionService {
private $con = null;
function __construct() {
// $this->con = mysqli_connect(DBConnectionService::$host, DBConnectionService::$username, DBConnectionService::$password, DBConnectionService::$dbname);
$this->con = mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME);
if (mysqli_connect_errno()) {
$this->con = null;
} else {
$this->updateCount(1);
$updateSql = "update connection_count set created = (created + 1) where id = 1";
mysqli_query($this->con, $updateSql);
}
}
function getConnection() {
if (!$this->con) {
return null;
} else {
return $this->con;
}
}
function __destruct() {
if ($this->con != null) {
$updateSql = "update connection_count set destroyed = (destroyed + 1) where id = 1";
mysqli_query($this->con, $updateSql);
$this->updateCount(2);
mysqli_close($this->con);
}
}
function exec($sql) {
$updateSql = "update connection_count set query = (query + 1) where id = 1";
mysqli_query($this->con, $updateSql);
$result = mysqli_query($this->con, $sql);
$this->updateCount(3);
return $result;
}
function updateCount($type) {
// $json = file_get_contents('count.db.json');
$json = file_get_contents(UtilityService::getBaseDirectory() . '/services/count.db.json');
$val = json_decode($json, true);
$create = $val["created"];
$destroy = $val["destroyed"];
$query = $val["query"];
if ($type == 1) {
$create = $val["created"] + 1;
} else if ($type == 2) {
$destroy = $val["destroyed"] + 1;
} else {
$query = $val["query"] + 1;
}
// $cb = fopen('count.db.json', 'w');
Logs::debug("DBConnection Service - " . UtilityService::getBaseDirectory() . '/services/count.db.json');
// $cb = fopen(UtilityService::getBaseDirectory() . '/services/count.db.json', 'w');
// fwrite($cb, '{"created":'.$create.',"destroyed":'.$destroy.',"query":'.$query.'}');
// fclose($cb);
}
}