2022-11-18

How do I solve this problem I got in using php class? [closed]

I am getting error connecting to database with class.

I moved the running program to another pc and got many problems. php versions are different.

I want to close db access with close. but error is coming.

<?php
class Antenler
{
    public $db;
    public $dizi = array();
    public function __construct() //başlangıçta buraya gir
    {
        try {
            $this->db = new PDO("mysql:host=127.0.0.1;dbname=db1;charset=utf8", 'root', 'root'); //localhost kısmı ip vererek kaydedebiliriz
            //echo "veri tabanı bağlantısı tamam";

        } catch (PDOException $e) {
            echo $e->getMessage();
        }
    }
    function Vb_VeriAl($id)
    {

        try {
            //db de bağlantısında hata alınırsa
            //$bilgilerimsor = $this->db->prepare("SELECT * from tabloo WHERE ID=(SELECT MAX(ID) AS max from tabloo WHERE Bolge_Id=$id ) AND Bolge_Id=$id");
            $bilgilerimsor = $this->db->prepare("SELECT * from de WHERE Bid=$id"); // veritabanında veri çekme
            $bilgilerimsor->execute();
            while ($bilgilerimcek = $bilgilerimsor->fetch(PDO::FETCH_ASSOC)) {
                $this->dizi[0] = $bilgilerimcek['d1']; //Şebeke dizinin 0. indisinde şebeke değeri saklı
                $this->dizi[1] = $bilgilerimcek['d2']; //frekans
                $this->dizi[2] = $bilgilerimcek['d3']; //jen gerilim
            }
            //echo "vb den veri aldımmm <br>";
            return $this->dizi;
        } catch (\Throwable $th) {
            echo 'hata: ' . $th->getMessage();
        }
    }
    public function __destruct()
    {
        $this->db->close;
    }
}
?>

Error:

enter image description here



No comments:

Post a Comment