php - Error : SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

one text

I'm having this error when i try to connect to mysql database using the PDO class, however, i can access the database using phpmyadmin and actually i created a database called company using phpmyadmin and i can access it using the command line

This is my code:

<?php
try {
    $dbhost = 'localhost';
    $dbname='company';
    $dbuser = 'root';
    $dbpass = '';
    $connect = new PDO(
"mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch (PDOException $e) {
    echo "Error : " . $e->getMessage() . "<br/>";
    die();
}

I tried everything on the internet and nothing worked with me.

phpVersion:7.2.24

mysqlVersion:5.7.36

OS: windows 10

server:wamp

phpmyadmin

Source