HTTP_Session and DB: "no database selected"
| From: | H Glenn Hatfield | Date: | Mon, 03 Apr 2006 15:54:26 +0000 |
| Subject: | HTTP_Session and DB: "no database selected" | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-23525@lists.php.net to get a copy of this message | ||
I'm trying to use HTTP_Session with the DB container.
Here is the code that I am using. (user/pass stripped out)
<?
require_once 'DB.php';
require_once 'HTTP/Session.php';
HTTP_Session::setContainer('DB',
'mysqli://user:pass@localhost/test');
HTTP_Session::start();
HTTP_Session::set('test_entry','it worked');
?>
This is the error I get:
DB Error: no database selected
I have tried researching this and found very little. What I have found suggests that the problem lies in disconnecting from the database somewhere else in the script. I'm clearly not doing this. Another thing I came across was an inquiry into whether it was happening on the first query or a subsequent one. For me, it is happening on the second query to be run.
I have been able to track down in the code where it is failing, but am unsure about the best way to fix it.
In version 0.5.1 of HTTP_Session, on line 210, I find the offending call:
$result = $this->db->getOne($query);
This is in the write() function, and here is a trimmed (and scrubbed) var_dump of the db object immediately before the call:
object(DB_mysqli)#2 (26) {
["phptype"]=>
string(6) "mysqli"
["dbsyntax"]=>
string(6) "mysqli"
["features"]=>
array(7) {
["limit"]=>
string(5) "alter"
["new_link"]=>
bool(false)
["numrows"]=>
bool(true)
["pconnect"]=>
bool(false)
["prepare"]=>
bool(false)
["ssl"]=>
bool(true)
["transactions"]=>
bool(true)
}
["dsn"]=>
array(9) {
["phptype"]=>
string(6) "mysqli"
["dbsyntax"]=>
string(6) "mysqli"
["username"]=>
string(7) "user"
["password"]=>
string(0) "pass"
["protocol"]=>
string(3) "tcp"
["hostspec"]=>
string(9) "localhost"
["port"]=>
bool(false)
["socket"]=>
bool(false)
["database"]=>
string(7) "test"
}
["autocommit"]=>
bool(true)
["transaction_opcount"]=>
int(0)
["_db"]=>
string(7) "test"
["fetchmode"]=>
int(1)
["fetchmode_object_class"]=>
string(8) "stdClass"
["was_connected"]=>
NULL
["last_query"]=>
string(99) "SELECT data FROM sessiondata WHERE id = '2b9e58d9310eafb4dfc92321946b6596' AND expiry >= 1144078144"
["options"]=>
array(8) {
["result_buffering"]=>
int(500)
["persistent"]=>
bool(false)
["ssl"]=>
bool(false)
["debug"]=>
int(0)
["seqname_format"]=>
string(6) "%s_seq"
["autofree"]=>
bool(false)
["portability"]=>
int(0)
["optimize"]=>
string(11) "performance"
}
}
The query listed in last_query comes from the read() method, which I have verified is being called immediately prior to the write() method. It seems that the connection *is* being broken, but I cannot track where. My solution has been to add this line of code at the top of the write() method:
$this->db->connect($this->db->dsn);
My 2 questions are these:
1) Where is it getting disconnected between the read() and write()?
2) Is there a better way to resolve this issue?
Apologies for the long post, but I felt it would be best to be thorough.
Any help is greatly appreciated.
Regards,
H Glenn Hatfield
glennh@inetz.com