Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db2 driver does not support blank username and password for *LOCAL connections #1031

Open
1 task done
NattyNarwhal opened this issue May 15, 2024 · 2 comments · May be fixed by #1034
Open
1 task done

db2 driver does not support blank username and password for *LOCAL connections #1031

NattyNarwhal opened this issue May 15, 2024 · 2 comments · May be fixed by #1034
Assignees
Labels
db2 IBM DB2 (Tier 1) enhancement
Milestone

Comments

@NattyNarwhal
Copy link

Description

A common idiom on IBM i is to use *LOCAL without a username and a password to establish a connection running with the same profile as the process. However, the ADOdb Db2 driver mandates that one must be set.

Environment

  • ADOdb version: 5.22.7
  • Driver or Module: Db2
  • Database type and version: Db2
  • PHP version: PHP 8.3.7
  • Platform: IBM i 7.5
  • I have tested that the problem is reproducible in the latest release / master branch / latest hotfix branch
    ⚠️ Keep only the applicable option(s), i.e. where you actually tested, and remove the others

Steps to reproduce

$adoDbDir = "vendor/adodb/adodb-php";
require "$adoDbDir/adodb.inc.php";

$db = newAdoConnection("db2");
var_dump($db->connect("*LOCAL", null, null));

$sql = "select * from qcustcdt";
$array = $db->getAll($sql);

print_r($array);

It doesn't seem to handle this very well, continuing on even though connect returned false and getting to a point where it uses false instead of the connection resource.

PHP Fatal error:  Uncaught TypeError: db2_set_option(): Argument #1 ($resource) must be of type resource, false given in /home/calvin/adodbtest/vendor/adodb/adodb-php/drivers/adodb-db2.inc.php:1591
Stack trace:
#0 /home/calvin/adodbtest/vendor/adodb/adodb-php/drivers/adodb-db2.inc.php(1591): db2_set_option()
#1 /home/calvin/adodbtest/vendor/adodb/adodb-php/adodb-lib.inc.php(1236): ADODB_db2->_query()
#2 /home/calvin/adodbtest/vendor/adodb/adodb-php/adodb.inc.php(1611): _adodb_debug_execute()
#3 /home/calvin/adodbtest/vendor/adodb/adodb-php/adodb.inc.php(1590): ADOConnection->_Execute()
#4 /home/calvin/adodbtest/vendor/adodb/adodb-php/adodb.inc.php(2294): ADOConnection->Execute()
#5 /home/calvin/adodbtest/vendor/adodb/adodb-php/adodb.inc.php(2087): ADOConnection->GetArray()
#6 /home/calvin/adodbtest/index.php(21): ADOConnection->GetAll()
#7 {main}
  thrown in /home/calvin/adodbtest/vendor/adodb/adodb-php/drivers/adodb-db2.inc.php on line 1591

Expected behavior

That it would connect fine.

Additional context

It appears it's because of this block in unpackParameters:

		if ($useCataloguedConnection
		&& (!$argDatabasename
		|| !$argUsername
		|| !$argPassword))
		{

			$errorMessage = 'For catalogued connections, provide ';
			$errorMessage.= 'database, username and password';
			$this->_errorMsg = $errorMessage;
			if ($this->debug)
				ADOConnection::outp($errorMessage);
			return null;

		}

This was introduced in the rewrite of this driver in 5.21.

@NattyNarwhal NattyNarwhal added the triage New issues not yet reviewed by ADOdb developers label May 15, 2024
@dregad dregad added the db2 IBM DB2 (Tier 1) label May 21, 2024
@dregad
Copy link
Member

dregad commented May 21, 2024

Same comment as #1032...
I'm sorry but I have zero knowledge of Db2, and no access to an instance of it for testing either, so I won't be able to help you much. Maybe @mnewnham will care to reply.

It doesn't seem to handle this very well, continuing on even though connect returned false

The error stack trace you provided is the result of calling getAll() on a failed connection. It is your responsibility to check connect()'s return value and take appropriate action (e.g. exit program) or use exceptions.

It appears it's because of this block in unpackParameters:
(snip)
This was introduced in the rewrite of this driver in 5.21.

@mnewnham mnewnham self-assigned this May 25, 2024
@mnewnham mnewnham added enhancement and removed triage New issues not yet reviewed by ADOdb developers labels May 25, 2024
@mnewnham mnewnham added this to the 5.22.8 milestone May 25, 2024
@mnewnham mnewnham linked a pull request May 25, 2024 that will close this issue
@dregad
Copy link
Member

dregad commented May 26, 2024

Thanks for the PR @mnewnham

@NattyNarwhal please test Mark's proposed fix in #1034 and let us know if it fixes your problem.

@NattyNarwhal NattyNarwhal linked a pull request May 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db2 IBM DB2 (Tier 1) enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants