ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.29k stars 1.35k forks source link

Disconnect from the database - not working. ( $conn->disconnect() ) #932

Open hitesh2911 opened 3 years ago

hitesh2911 commented 3 years ago

I have to many queries which are executed on a single API hit, however since these there queries on different DB , i need to close the connection once the query is executed.

When i use the $conn->disconnect(), any further queries should not be executed. However the connection is not closed and the further queries are executed.

Please find the sample code for below.

`<?php

try { ini_set('display_errors', 1);

require_once '/cmui/appscommon/resource/php/lib/MysqliDbV3.php';

$conn = new MysqliDbV3("localhost", "root", "root", "localdb");
$conn->setTrace(true);

$query = "SELECT  * FROM Test WHERE  userId = '1324'  LIMIT 1";

$data = $conn->rawQuery($query);
$time = round($conn->trace[0][1], 2);
if ($conn->getLastErrno() === 0) {
    echo "<br>Filepath:$file, Status:SUCCESS:$query ,Timetaken:$time secs.";
} else {
    echo "<br>Filepath:$file, Status:ERROR:$query , Response:" . $conn->getLastError();
}

if ($conn) {
    $conn->disconnect();
    echo "<br>Closed connection";
}

$data = $conn->rawQuery($query);
$time = round($conn->trace[0][1], 2);
if ($conn->getLastErrno() === 0) {
    echo "<br>Filepath:$file, Status:SUCCESS:$query ,Timetaken:$time secs.";
} else {
    echo "<br>Filepath:$file, Status:ERROR:$query , Response:" . $conn->getLastError();
}

} catch (mysqli_sql_exception $ex) { $data = array("error" => $ex->getMessage()); echo "Filepath:$file, Status:ERROR : $query , Response:" . $e->getMessage(); $conn->disconnect(); }

`