PEAR DB: mssql and default database

From: Date: Thu, 20 Jan 2005 20:53:15 +0000
Subject: PEAR DB: mssql and default database
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-35647@lists.php.net to get a copy of this message
Hello, When connecting to an MSSQL DBMS, it's not always required to select a specific database to work with: MSSQL support assignment of a default database to a database user. Hence, a DSN like mssql://login:pw@server will work. However, as soon as one starts posting queries to such a PEAR DB Connection, things will start to fail for subtle reasons. In DB/mssql.php there is currently the following lines in simpleQuery: if (!@mssql_select_db($this->_db, $this->connection)) { return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED); } If using a DSN like the one mentioned above, we will effectively get: mssql_select_db(NULL); // fails with very strange error message It took me a while to figure out what was happening. And I propose that DB_mssql's constructor bails out if $dnsinfo['database'] is null or otherwise empty, to save developer time. Alternatively, I suggest that the following code be changed in DB_mssql's simpleQuery method: Before: if (!@mssql_select_db($this->_db, $this->connection)) { return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED); } After: if (!empty($this->_db)) { if (!@mssql_select_db($this->_db, $this->connection)) { return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED); } } However, the latter solution may be dangerous with persistent connections? - I guess there is a reason for simpleQuery explicitly selecting database for each query? -- Greetings from Troels Arvin, Copenhagen, Denmark

« previous php.pear.dev (#35647) next »