将PDO对象发送到类[关闭]

I'm new here... I have a problem using PDO object in my class... Here is the code: Creating PDO connection:

<?php 
    try {
        $konekcija = new PDO(DSN, USERNAME, PASSWORD);
        $konekcija->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        echo "Error connecting to database: " . $e->getMessage();
        die();
    }
?>

Class:

class Nastavnik
{
    private $zvanje = "";
    private $konekcija;

    public function __construct($konekcija){
        $this->konekcija = $konekcija;
    }

    public function registracija($korIme, $lozinka, $ime, $prezime, $telefon, $email, $zvanje, $tipKorisnika){
        $upitRegistracija = "INSERT INTO projekat_vst.korisnici (kor_ime, lozinka, ime, prezime, telefon, email, zvanje, tip_korisnika) 
                                                            VALUES (:korIme, :lozinka, :ime, :prezime, :telefon, :email, :zvanje, :tip_korisnika);";
        try {
            $stmt = $konekcija->prepare($upitRegistracija);
            $stmt->execute($korIme, $lozinka, $ime, $prezime, $telefon, $email, $zvanje, $tipKorisnika);
            return 1;
        } catch (PDOException $e) {
            echo "Greška pri kreiranju korisnika." . $e->getMessage();
            return 0;
        }
    }


}

And this is code creating new class:

$korisnik = new Nastavnik($konekcija);

When I try to create new instance of class Nastavnik I get this message:

Notice: Undefined variable: konekcija in D:\php_dev\xampp\htdocs\projekatVST\includes\klasaNastavnik.php on line 24

I don't see where am I making mistake... Thank you for helping! :)

It's not $konekcija but $this->konekcija.

Youre missing $this:

$stmt = $konekcija->prepare($upitRegistracija);

Should be:

$stmt = $this->konekcija->prepare($upitRegistracija);