简体   繁体   English

odbc_connect设置DefaultSchema

[英]odbc_connect set DefaultSchema

I want to try to define the schema to set list of libraries where I can search the table on which make the query sql. 我想尝试定义模式来设置库列表,我可以在其中搜索查询sql的表。

at the momenti I can connect on my DB2 into IBMi with this string-connection: 在momenti我可以通过这个字符串连接将我的DB2连接到IBMi:

 $user = 'USER';
 $password = 'PWD';
 $hostname = '192.168.1.100';
 $db = 'S6528B5A';
 $conn_string = "DRIVER={iSeries Access ODBC  Driver};
                 SYSTEM=$hostname;
                 PROTOCOL=TCPIP;
                 UID=$user;
                 PWD=$password;
                 DATABASE=$db;
                 DefaultSchema={LIB1,LIB2};";

the connection is successfully established i get Resource id #3 but when i try to execute sql query: 连接成功建立我获得资源ID#3,但当我尝试执行sql查询时:

$sql = 'SELECT * FROM FILE1';
$rows = odbc_exec($conn, $sql);

I get an error SQL state S0002 where the file is not found (as if searching for the file in wrong library, search in the library with the same user name that opened the connection) 我收到一个错误SQL状态S0002,其中找不到该文件(好像在错误的库中搜索该文件,在库中搜索与打开连接的用户名相同)

how can set my environment at the first connectione and than execute query? 如何在第一个连接处设置我的环境而不是执行查询?

Use this connection string to enable system naming and to not set a default library: 使用此连接字符串启用系统命名并且不设置默认库:

$conn_string = "DRIVER={iSeries Access ODBC  Driver};
  SYSTEM=$hostname;
  PROTOCOL=TCPIP;
  UID=$user;
  PWD=$password;
  Naming=1;
  DefaultSchema=,LIB1,LIB2;";

Client Access ODBC: Default Libraries Setting 客户端访问ODBC:默认库设置

ODBC connection string keywords ODBC连接字符串关键字

Excerpts of the relevant parts are: 相关部分的摘录如下:

With SQL naming convention, the operating system does not perform a library list search to locate an unqualified object. 使用SQL命名约定,操作系统不会执行库列表搜索以查找非限定对象。 If a default collection is defined, the default collection is used to resolve unqualified SQL statements. 如果定义了缺省集合,则使用缺省集合来解析非限定SQL语句。

... ...

With the SYS naming convention, the unqualified SQL statements go to the default collection. 使用SYS命名约定,非限定SQL语句将转到缺省集合。 If there is no default collection, the current library is used. 如果没有默认集合,则使用当前库。 If no current library is specified, the library list is used. 如果未指定当前库,则使用库列表。

... ...

Default Collection 默认集合

A job attribute set by ODBC that determines the library used when processing SQL statements that contain unqualified SQL names. ODBC设置的作业属性,用于确定处理包含非限定SQL名称的SQL语句时使用的库。 When a default collection is set all unqualified objects except procedures, functions and types must reside in the default collection, regardless of naming convention. 设置默认集合时,除了过程,函数和类型之外的所有非限定对象都必须驻留在默认集合中,而不管命名约定如何。

... ...

How can I get ODBC to search the library list? 如何让ODBC搜索库列表?

As explained above, edit the ODBC data source and set system naming to SYS. 如上所述,编辑ODBC数据源并将系统命名设置为SYS。 The default library must be empty, or on versions older than R510, the default libraries setting must start with a comma so that no default collection is defined (for example, ",MYLIB1, MYLIB2"). 默认库必须为空,或者在早于R510的版本上,默认库设置必须以逗号开头,以便不定义默认集合(例如,“,MYLIB1,MYLIB2”)。


Odbc connection string format, not finding files Odbc连接字符串格式,无法查找文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM