112 lines
2.7 KiB
PHP
112 lines
2.7 KiB
PHP
<?php
|
|
|
|
class Dropdown
|
|
{
|
|
private $host;
|
|
private $username;
|
|
private $password;
|
|
private $dbname;
|
|
private $connection;
|
|
|
|
// Establish connection
|
|
public function __construct()
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Load Composer and .env
|
|
|--------------------------------------------------------------------------
|
|
| This file is inside: cmccopiaoriginale/public/ddown/
|
|
| vendor and .env are inside: cmccopiaoriginale/
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../../');
|
|
$dotenv->safeLoad();
|
|
|
|
$this->host = $_ENV['DB_HOST'] ?? getenv('DB_HOST') ?? 'localhost';
|
|
$this->username = $_ENV['DB_USERNAME'] ?? getenv('DB_USERNAME') ?? '';
|
|
$this->password = $_ENV['DB_PASSWORD'] ?? getenv('DB_PASSWORD') ?? '';
|
|
$this->dbname = $_ENV['DB_DATABASE'] ?? getenv('DB_DATABASE') ?? '';
|
|
|
|
try {
|
|
$this->connection = new mysqli(
|
|
$this->host,
|
|
$this->username,
|
|
$this->password,
|
|
$this->dbname
|
|
);
|
|
|
|
if ($this->connection->connect_error) {
|
|
throw new Exception($this->connection->connect_error);
|
|
}
|
|
|
|
$this->connection->set_charset("utf8mb4");
|
|
} catch (Exception $e) {
|
|
echo "Connection error " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Fetch all article type 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 depending on article type id
|
|
public function fetchModel($idarticletype)
|
|
{
|
|
$data = null;
|
|
|
|
$idarticletype = (int)$idarticletype;
|
|
|
|
$query = "SELECT * FROM modelarticle WHERE idarticletype = $idarticletype";
|
|
|
|
if ($sql = $this->connection->query($query)) {
|
|
while ($rows = mysqli_fetch_assoc($sql)) {
|
|
$data[] = $rows;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
// Fetch characteristic records from database depending 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;
|
|
}
|
|
}
|