Is there a way to specify the schema to use with PHP's db2_connect
method? Apparently it connects to the default schema, though it seems like there should be an option to specify schema in the connect string.

- 9,888
- 15
- 81
- 148
-
you connect to a db not a schema. can you add some details of what your trying to accomplish – Oct 13 '15 at 19:33
-
@Dagon-- then after you connect, you'd set schema as a separate command? – user101289 Oct 13 '15 at 19:37
-
correct, there's no connect db + select schema in one function. but as below you can defult – Oct 13 '15 at 20:01
2 Answers
You cannot do this using db2_connect()
, however, there are other options.
Issue the
set schema
statement:db2_exec($yourconnection, 'SET SCHEMA WHATEVER')
Set the default schema in the
db2cli.ini
file using theCurrentSchema
keyword.Similarly, use
CurrentSchema
parameter in thedb2dsdriver.cfg
file.
Note that the latter two methods will affect all connections, including those made by other CLI/ODBC applications on that machine.

- 18,234
- 16
- 48
- 57
Take a look at my answer on SO here: https://stackoverflow.com/a/31082570/652519
It might help get things setup and configured correctly. There is an option in the odbc.ini file called Default Libraries
. I've never had the need to change this, but this may be what you're looking for.
There's also an option for the database. In the above referenced answer, the database
value in the odbc.ini file is blank, which I would assume can be changed. Again, I haven't had a need to change it, so you can tinker with it to test.