连接到IBM AS / 400 DB2数据库 [英] Connecting to an IBM AS/400 DB2 Database

查看:1860
本文介绍了连接到IBM AS / 400 DB2数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP的 ODBC驱动程序从Ubuntu服务器连接到客户端的IBM AS / 400 DB2数据库。我也安装了 unixODBC 。我的 odbcinst.ini 如下所示:

  [IBM DB2 ODBC DRIVER] 
说明= ODBC 5.1驱动程序
驱动程序= /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
FileUsage = 1

而我的 odbc.ini 如下所示:

  [IBM DB2 ODBC DRIVER] 
驱动程序= IBM DB2 ODBC DRIVER
描述= ODBC 5.1驱动程序DSN

现在,我的代码是:

  $ server = '12 .345.678.90' / IP 
$ port ='446'// PORT
$ username ='my_username';
$ password ='my_password';

$ connect = odbc_connect(DRIVER = {IBM DB2 ODBC DRIVER}; System = $ server:$ port; Uid = $ username; Pwd = $ password;,$ username,$ password)

if(!$ connect)
echo'Can not Connect!';
else
echo'Connected!';

我得到的错误是:

 警告:odbc_connect():SQL错误:[unixODBC] [MySQL] [ODBC 5.1驱动程序]访问被拒绝为用户'my_username'@'localhost'(使用密码:是),SQL状态S1000在SQLConnect 

我也尝试使用PDO ODBC驱动程序。这是我得到的错误:

  $ connect = new PDO(odbc:DRIVER = {IBM DB2 ODBC DRIVER}; HOSTNAME = $ server; PORT = $ port; Uid = $ username; Pwd = $ password); 

致命错误:未捕获的异常'PDOException'与消息'SQLSTATE [HY000] SQLDriverConnect:1045 [unixODBC] [MySQL] [ODBC 5.1驱动程序]访问被拒绝为用户'my_username'@'localhost'(使用密码:YES)'in /var/www/test_file.php堆栈跟踪:#0 /var/www/test_file.php:PDO-> __ construct('odbc:DRIVER = {IB ...')#1 {main扔在/var/www/test_file.php

我在这里做错什么?我需要使用其他驱动程序,因为用户名和密码正确,我看到客户端使用我拥有的用户名和密码登录到数据库。我认为用户名和密码错误,因为它表示拒绝访问用户。情况似乎不是这样。可能还有别的事情是错的。



感谢您的帮助。我希望我很清楚这个问题。谢谢!

解决方案

您的odbcinst.ini文件是使用MySQL ODBC驱动程序:

  Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so 

,但您需要使用 iSeries Access ODBC 驱动程序。您获得访问被拒绝用户消息的原因是因为您尝试使用IBM i的凭据连接到MySQL数据库。



以下是有关如何连接到Ubuntu Ubuntu上的DB2(在IBM i上)的分步说明:



下载免费IBM的iSeriesAccess-6.1.0-1.2.i386.rpm 文件(您必须创建一个免费的帐户才能获得) - 我确定有更多的最新版本比6.1.0-1.2)



将RPM文件转换为Ubuntu了解的内容: sudo alien iSeriesAccess-6.1.0-1.2.i386 .rpm



安装生成的.deb: sudo dpkg -i iseriesaccess_6.1.0-2.2_i386.deb



将安装的iSeries库复制到Ubuntu要求的位置: sudo cp / opt / ibm / iSeriesAccess / lib / * / usr / lib



编辑 /etc/odbc.ini 文件以包含:

  [primary] 
说明= primary
驱动程序= iSeries访问ODBC驱动程序
系统= IP_ADDRESS
用户ID = USERNAME
密码= PASSWORD
命名= 1
DefaultLibraries = QGPL
Database = XXXXXXXXXX
ConnectionType = 0
CommitMode = 2
ExtendedDynamic = 0
DefaultPkgLibrary = QGPL
DefaultPackage = A / DEFAULT(IBM),2,0,1 ,0,512
AllowDataCompression = 1
LibraryView = 0
AllowUnsupportedChar = 0
ForceTranslation = 0
Trace = 0
pre>

编辑 /etc/odbcinst.ini 文件以包含:

  [iSeries Access ODBC驱动程序] 
说明=适用于Linux ODBC驱动程序的iSeries访问
驱动程序= /usr/lib/libcwbodbc.so
安装程序= / usr / lib / libcwbodbcs.so
NOTE1 =如果usi ng unixODBC 2.2.11或更高版本,您希望32位和64位ODBC驱动程序共享DSN,
NOTE2 =以下Driver64 / Setup64关键字将提供该支持。
Driver64 = /usr/lib/lib64/libcwbodbc.so
Setup64 = /usr/lib/lib64/libcwbodbcs.so
线程= 2
DontDLClose = 1
UseCount = 1

然后创建与PDO的连接:

  $ pdo = new PDO(odbc:DRIVER = {iSeries Access ODBC Driver}; SYSTEM = $ server; PROTOCOL = TCPIP,$ username,$ password) 


I'm trying to connect to a client's IBM AS/400 DB2 Database from an Ubuntu Server using PHP's ODBC Driver. I have the unixODBC installed as well. My odbcinst.ini looks like this:

[IBM DB2 ODBC DRIVER]
Description = ODBC 5.1 Driver for Database
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
FileUsage = 1

And my odbc.ini looks like this:

[IBM DB2 ODBC DRIVER]
Driver = IBM DB2 ODBC DRIVER
Description = ODBC 5.1 Driver DSN

Now, my code to connect is:

$server = '12.345.678.90' //IP
$port = '446' //PORT
$username = 'my_username';
$password = 'my_password';

$connect = odbc_connect("DRIVER = {IBM DB2 ODBC DRIVER};System=$server:$port;Uid=$username;Pwd=$password;", $username, $password);

if(!$connect)
    echo 'Cannot Connect!';
else
    echo 'Connected!';

The error I get is this:

Warning: odbc_connect(): SQL Error: [unixODBC][MySQL][ODBC 5.1 Driver]Access denied for user 'my_username'@'localhost' (using password: YES), SQL state S1000 in SQLConnect

I tried using the PDO ODBC Driver also. This is the error I get:

$connect = new PDO("odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=$server;PORT=$port;Uid=$username;Pwd=$password");

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] SQLDriverConnect: 1045 [unixODBC][MySQL][ODBC 5.1 Driver]Access denied for user 'my_username'@'localhost' (using password: YES)' in /var/www/test_file.php Stack trace: #0 /var/www/test_file.php: PDO->__construct('odbc:DRIVER={IB...') #1 {main} thrown in /var/www/test_file.php

Am I doing something wrong here? Do I need to use some other driver, because the username and password are correct, I saw the client log in to the database using the username and password I have. I thought the username and password were wrong because it says Access Denied for user. It doesn't seem to be the case. There might be something else that's wrong.

Thank you for your help. I hope I made the problem very clear. Thanks!

解决方案

Your odbcinst.ini file is saying to use the MySQL ODBC driver:

Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so

but you need to use the iSeries Access ODBC driver. The reason you're getting an Access Denied for User message is because you're trying to connect to your MySQL database with credentials for the IBM i.

Here are step by step instructions for how to connect to DB2 for i (on the IBM i) on Ubuntu:

Download the free iSeriesAccess-6.1.0-1.2.i386.rpm file from IBM (you'll have to create a free account to get it - and I'm sure there is a more recent version than 6.1.0-1.2)

Convert the RPM file to something Ubuntu understands: sudo alien iSeriesAccess-6.1.0-1.2.i386.rpm

Install the resulting .deb: sudo dpkg -i iseriesaccess_6.1.0-2.2_i386.deb

Copy the installed iSeries libraries to where Ubuntu expects them: sudo cp /opt/ibm/iSeriesAccess/lib/* /usr/lib

Edit the /etc/odbc.ini file to contain:

[primary]
Description             = primary
Driver                  = iSeries Access ODBC Driver
System                  = IP_ADDRESS
UserID                  = USERNAME
Password                = PASSWORD
Naming                  = 1
DefaultLibraries        = QGPL
Database                = XXXXXXXXXX
ConnectionType          = 0
CommitMode              = 2
ExtendedDynamic         = 0
DefaultPkgLibrary       = QGPL
DefaultPackage          = A/DEFAULT(IBM),2,0,1,0,512
AllowDataCompression    = 1
LibraryView             = 0
AllowUnsupportedChar    = 0
ForceTranslation        = 0
Trace                   = 0

Edit the /etc/odbcinst.ini file to contain:

[iSeries Access ODBC Driver]
Description     = iSeries Access for Linux ODBC Driver
Driver          = /usr/lib/libcwbodbc.so
Setup           = /usr/lib/libcwbodbcs.so
NOTE1           = If using unixODBC 2.2.11 or later and you want the 32 and 64-bit ODBC drivers to share DSN's,
NOTE2           = the following Driver64/Setup64 keywords will provide that support.
Driver64        = /usr/lib/lib64/libcwbodbc.so
Setup64         = /usr/lib/lib64/libcwbodbcs.so
Threading       = 2
DontDLClose     = 1
UsageCount      = 1

And then to create the connection with PDO:

$pdo = new PDO("odbc:DRIVER={iSeries Access ODBC Driver};SYSTEM=$server;PROTOCOL=TCPIP", $username, $password);

这篇关于连接到IBM AS / 400 DB2数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆