Why can't I connect to database using PHP Slim framework?
<p>I'm new to PHP Slim framework and I've written code to connect to database but it shows the following error in console (The database exists, still getting error):</p>

<p><a href="https://i.stack.imgur.com/OIiaA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OIiaA.png" alt="enter image description here"></a></p>

<p>Here's my code:</p>

<pre><code>&lt;?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require '../vendor/autoload.php';

function dbConnect(){
    $host='127.0.0.1';
    $user='root';
    $pass='';
    $dbname='testdbmysql';
    $pdo= new PDO("mysql:host=$host; dbname= $dbname", $user, $pass);
    $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    return $pdo;
}

$app = new \Slim\App;
$app-&gt;post('/hello/{id}', function (Request $request, Response $response, $args) {
    echo "hello";
    $names = $request-&gt;getParsedBody();
    $db=dbConnect();
    $names_arr=[];
    $names_arr['name1']= filter_var($names['name1'], FILTER_SANITIZE_STRING);
    $names_arr['name2']= filter_var($names['name2'], FILTER_SANITIZE_STRING);
    $response-&gt;getBody()-&gt;write("Hello , ".$names_arr['name1']);
    $query=mysqli_prepare($db, "INSERT into info(fname, lname) VALUES(?, ?)");
    mysqli_stmt_bind_param($query, "ss", $names_arr['name1'], $names_arr['name2']);
    $result=mysqli_stmt_execute($query);
    $rows=mysqli_stmt_insert_id($query);
    echo "Rows: ".$rows;
    return $response;
});
$app-&gt;run();
?&gt;
</code></pre>

<p>When I searched on Internet, I found solutions to same error caused by Laravel framework, but not about Slim. Is there something I can do?</p>