Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to close connection? #198

Open
catchem99 opened this issue Jan 1, 2019 · 2 comments
Open

How to close connection? #198

catchem99 opened this issue Jan 1, 2019 · 2 comments

Comments

@catchem99
Copy link

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

@dragonattack
Copy link

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.

@liamka
Copy link

liamka commented Oct 30, 2021

@usmanhalalit ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants