pixie icon indicating copy to clipboard operation
pixie copied to clipboard

How to close connection?

Open catchem99 opened this issue 7 years ago • 3 comments

Can pixie close a connection? It's not in the documentation..

catchem99 avatar Jan 01 '19 02:01 catchem99

There's no simple way to do this in PDO. Documentation suggests:

To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted—you do this by assigning null to the variable that holds the object.

Note: If there are still other references to this PDO instance (such as from a PDOStatement instance, or from other variables referencing the same PDO instance), these have to be removed also (for instance, by assigning null to the variable that references the PDOStatement).

I didn't manage to do this, so I destroy this connection from mysql itself.

public function close()
{
	// this line does the job
	try { $this->pdo->query('KILL CONNECTION_ID()'); } catch (\PDOException $e) {}
	// this should close the connection, but doesn't.
	return $this->pdo = $this->connection = $this->container = $this->pdoStatement = null;
}

try/catch to dismiss Fatal error: 1317 Query execution was interrupted May be someone can do it correctly with nulls to make it more cleaner. But it tested and works with this mysql trick.

dragonattack avatar Aug 17 '21 00:08 dragonattack

@usmanhalalit ?

liamka avatar Oct 30 '21 12:10 liamka