Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fSQLException when switching DB

posted by ben 9 years ago

code:

$db1 =new fDatabase('mssql', 'admin', $config->mssql->user, $config->mssql->password, $config->mssql->host);
$db2 =new fDatabase('mssql', 'account', $config->mssql->user, $config->mssql->password, $config->mssql->host);

$result= $db1->query("SELECT * from admin_users where username='benstone'");
$adminUserId= $result->fetchScalar();

$result= $db2->query("SELECT user_no from USER_PROFILE where user_id='benstone'");
$accountId = $result->fetchScalar();

$result= $db1->query("SELECT * from admin_users where username='benstone'");
$adminUserId= $result->fetchScalar();

error message:

Uncaught fSQLException
----------------------
{doc_root}\\testmultidb.php(14): fDatabase->query('SELECT * from a...')
{doc_root}\\include\\lib\\flourish\\fDatabase.php(2530): fDatabase->run('SELECT * from a...', 'fResult')
{doc_root}\\include\\lib\\flourish\\fDatabase.php(2565): fDatabase->performQuery('SELECT * from a...', Object(fResult), Array)
{doc_root}\\include\\lib\\flourish\\fDatabase.php(2195): fDatabase->checkForError(Object(fResult), NULL)
{doc_root}\\include\\lib\\flourish\\fDatabase.php(403)
MSSQL error ({null}) in SELECT * from admin_users where username='benstone'

Notes:


Hope someone can help me. Thanks!

found the fix:

works with complete table name.

SELECT * from admin.dbo.admin_users where username='benstone'
posted by autobox 9 years ago

It looks like there is some bug at work here. Can you tell me the output of the following command?

fCore::expose($db1->getExtension());
posted by wbond 9 years ago

output is:

mssql
posted by anonymous 9 years ago

Thanks for taking the time to report this. The bug was that the mssql extension was reusing the database connection since it was to the same server. I changed fDatabase in r890 to force a new connection, so you shouldn't have this problem anymore.

posted by wbond 9 years ago