<?php

header('content-type:text/html; charset=utf8');
$dbhost =  getenv('dbhost');
$dbname =  getenv('dbname');
$dbusername =  getenv('dbusername');
$dbpassword = getenv('dbpassword');
//$connectionString = getenv('azureBlob');


/* $dbhost = "hanyu-db.mysql.database.azure.com";
$dbusername = "nchc";
$dbname = "nchc_nz"; 
$dbpassword = "hanyuVr2498"; */
$connectionString = "";

abstract class LinkDBMYSQL
{
    protected $conn;
    
    /*
     *  資料庫連線
     */
/*
    protected function Connect()
    {
        header('content-type:text/html; charset=utf8');
        $dbquery = "";     
        $dbhost = "hanyu-db.mysql.database.azure.com";       
        $dbusername = "nchc";
        $dbname = "nchc_nz"; 
        $dbpassword = "hanyuVr2498";
        
        try {
            // LOCAL DB CONNCTION STRING 
            $this->conn = new mysqli($dbhost, $dbusername, $dbpassword, $dbname);
        } catch (mysqli_sql_exception $e) {
            // SHOW THE ERROR MESSAGE
            echo "连接数据库时发生错误：" . $e->getMessage();
        }

        // 檢查連線是否成功
        // if ($conn->connect_error) {
        //     die("連接失敗：" . $conn->connect_error);
        // } else {
        //     echo "連接成功";
        // }
    }
*/
    /*
     *  解除連線
     */

    /* protected function Disconnect()
    {
        return $this->conn = NULL;
    }

    public function executeQuery($sql)
    {
        $this->Connect(); // 確保在執行查詢前已經連接到資料庫
        $result = $this->conn->query($sql);

        if ($result === false) {
            // 查詢失敗
            echo "查询错误：" . $this->conn->error;
            return false;
        } else {
            // 查詢成功，處理結果
            $data = $result->fetch_all(MYSQLI_ASSOC);
            $result->free();
            $this->Disconnect(); // 查詢完成後斷開連接
            return $data;
        }
    } */
}
