Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

MODX DBAPI->disconnect() is incomplete #223

Closed
juliolopez78 opened this issue Mar 25, 2014 · 1 comment
Closed

MODX DBAPI->disconnect() is incomplete #223

juliolopez78 opened this issue Mar 25, 2014 · 1 comment

Comments

@juliolopez78
Copy link
Contributor

Hello,

Just working with the DBAPI to create and close some addtional DB connections and I came across a bug.

Currently, the disconnect() method does not properly update the DBAPI properties $conn and $isConnected. This generates an error if you want to use the same instance of the DBAPI later on after closing the DB connection for a new connection to the same DB. For example:

$dbapi = new DBAPI('localhost', 'some_db', 'some_db_user', '0bfu$c@t3d-pw0rd');
$dbapi->connect();
// get some data;
$dbapi->disconnect();
// do something with the data, then reconnect to get different data
$dbapi->connect();
// MODX parse error!

The problem is ocurring because disconnect() isn't setting $conn to null and $isConnected to false, it's just closing the mysql connection. $conn remains a resource, but since the connection is closed, it can't be used again, but the code in the connect method works, because it is still a resource. Same goes for $isConnected, it remains true, so any code that tries to evaluate this, evaluates it in error.

Anyway, I propose a simple reset within the disconnect() method, change it from this:

function disconnect() {
    @ mysql_close($this->conn);
}

to this:

function disconnect() {
    @ mysql_close($this->conn);
    $this->conn = null;
    $this->isConnected = false;
}

This way everything ends nicely and the DBAPI object can be reused safely for subsequent connections.

Dmi3yy added a commit that referenced this issue May 19, 2014
@Dmi3yy
Copy link
Collaborator

Dmi3yy commented May 19, 2014

done

@Dmi3yy Dmi3yy closed this as completed May 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants