fixed db connection

This commit is contained in:
2026-09-10 10:28:24 +02:00
parent 62bfb4d77f
commit 88c454c5d4
4 changed files with 95 additions and 216 deletions
+17 -80
View File
@@ -1,19 +1,27 @@
<?php
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
if (!isset($_ENV['DB_HOST'])) {
Dotenv\Dotenv::createImmutable(__DIR__ . '/../../')->safeLoad();
}
Class Dropdown
{
private $host = 'localhost';
private $username = 'u00wiumd4xnrd';
private $password = 'ukowysga7w5x';
private $dbname = 'dbcov4clvrmrzn';
private $host;
private $username;
private $password;
private $dbname;
private $connection;
//establish connection
public function __construct()
{
$this->host = $_ENV['DB_HOST'] ?? 'localhost';
$this->username = $_ENV['DB_USERNAME'] ?? '';
$this->password = $_ENV['DB_PASSWORD'] ?? '';
$this->dbname = $_ENV['DB_DATABASE'] ?? '';
try
{
$this->connection = new mysqli($this->host, $this->username, $this->password, $this->dbname);
@@ -22,75 +30,4 @@ Class Dropdown
{
echo "Connection error " . $e->getMessage();
}
}
//fetch all country records from database
public function fetchCountry()
{
$data = null;
$query = "SELECT * FROM article_type ORDER BY article_type.name_articletype";
if ($sql = $this->connection->query($query))
{
while ($rows = mysqli_fetch_assoc($sql))
{
$data[] = $rows;
}
}
return $data;
}
//fetch model records from database depend upon country id
public function fetchModel($idarticletype)
{
$data = null;
$query = "SELECT * FROM modelarticle WHERE idarticletype='".$idarticletype."' ";
if ($sql = $this->connection->query($query))
{
while ($rows = mysqli_fetch_assoc($sql))
{
$data[] = $rows;
}
}
return $data;
}
//fetch Charact records from database depend on article type
public function fetchCharact($idarticletype)
{
$data = null;
$idarticletype = (int)$idarticletype;
$query = "
SELECT DISTINCT
ac.*
FROM article_characteristic ac
INNER JOIN standards s
ON s.idarticlecharacteristic = ac.idarticlecharacteristic
AND s.idarticletype = ac.idarticletype
WHERE ac.idarticletype = $idarticletype
AND s.active = 'Y'
ORDER BY ac.name_articlecharacteristic
";
if ($sql = $this->connection->query($query))
{
while ($rows = mysqli_fetch_assoc($sql))
{
$data[] = $rows;
}
}
return $data;
}
}
?>
}