usmanhalalit / pixie

Database query builder for PHP, framework agnostic, lightweight and expressive.
MIT License
672 stars 180 forks source link

How to close connection? #198

Open catchem99 opened 5 years ago

catchem99 commented 5 years ago

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

dragonattack commented 3 years ago

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 commented 3 years ago

@usmanhalalit ?