PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #49

sybase simpleQuery is broken

Details

Submitted2003-09-30 11:56 UTC
Fromr dot vanicek at seznam dot cz
Assigneddanielc
StatusClosed
PackageDB
PHP Version4.3.3
OSDebian GNU/Linux woody
Roadmaps(Not assigned)

Comments

[2003-09-30 11:56 UTC] r dot vanicek at seznam dot cz

Description:
------------
simpleQuery method in the sybase class always returns an error. I have discovered that the problem is caused by the sybase_select_db call which always fails with the message:

Warning: sybase_select_db(): Sybase message: Incorrect syntax near 'use'. (severity 15) in /usr/local/lib/php/DB/sybase.php on line 220

The fix is to comment out the if statement, because it is not needed (the database is already selected, after calling connect). The previous version (RC1) did not have this statement (select_db) inside the simpleQuery and my opinion is that it should not be here (it is strange to change the db with every command).

I hope your day goes well, Roman

Reproduce code:
---------------
require_once "DB.php";

$GLOBALS['dsn'] = array(
'phptype'=>'sybase',
'username'=>'user',
'password'=>'PSWD',
'hostspec'=>'servername',
'database'=>'dbname',
'charset'=>'iso-8859-2');

$GLOBALS['kkDB'] = @DB::connect($GLOBALS['dsn'],false);
$GLOBALS['kkDB']->query('set dateformat dmy');

$res = $kkDB->query("select * from ANYTABLE");
var_dump($res);

[2003-11-14 14:09 UTC] fielker at informatik dot fh-augsburg dot de

Hi i found out where the problem is:

simple_query mages use of "$this->_db" which is not
initalized. So I looked at the mysql code. In connect()
$this->_db is set to $dsninfo['database']. So here the
fix.

Pleas PEAR guys add this to the next release of DB. THX.

if ($dsninfo['database']) {
if (!@sybase_select_db($dsninfo['database'],
$conn)) {
return
$this->raiseError(DB_ERROR_NODBSELECTED, null,
null, null,
sybase_get_last_message());
}
}

if ($dsninfo['database']) {
if (!@sybase_select_db($dsninfo['database'],
$conn)) {
return
$this->raiseError(DB_ERROR_NODBSELECTED, null,
null, null,
sybase_get_last_message());
}
$this->_db = $dsninfo['database']; //
-<<<<<<<<<<<<<<<<<< ADD THIS (line 114)
}

[2003-11-20 17:49 UTC] trevor dot dennis at eds dot com

Even with the code fix given, you must now still pass the database name to the connect string where you didn't have to before.

Normally one relies on Sybase to automatically place you in your correct default database upon connection based on the user login name. Maybe the connect code should query the current database if it was not defined on the DSN string.

select db_name()

I agree with the first statement though. It should not be setting the database before every simple query. This may cause issues with transactions or at the very least will slow down processing if you're doing a large many row insert.