我正在尝试使用PHP的ODBC驱动程序从ubuntu服务器连接到客户端的IBM AS / 400 DB2数据库.我也安装了unixODBC.我的odbcinst.ini看起来像这样:
[IBM DB2 ODBC DRIVER] Description = ODBC 5.1 Driver for Database Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so FileUsage = 1
而我的odbc.ini看起来像这样:
[IBM DB2 ODBC DRIVER] Driver = IBM DB2 ODBC DRIVER Description = ODBC 5.1 Driver 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 'Cannot Connect!'; else echo 'Connected!';
我得到的错误是这样的:
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
我也试过使用PDO ODBC Driver.这是我得到的错误:
$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
我在这里做错了吗?我是否需要使用其他驱动程序,因为用户名和密码是正确的,我看到客户端使用我拥有的用户名和密码登录数据库.我认为用户名和密码错误,因为它说用户拒绝访问.似乎并非如此.可能还有别的东西是错的.
感谢您的帮助.我希望我能很清楚地解决这个问题.谢谢!
你的odbcinst.ini文件说使用MysqL ODBC驱动程序:
原文链接:/ubuntu/349164.htmlDriver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
但您需要使用iSeries Access ODBC驱动程序.您获得“拒绝访问用户”消息的原因是因为您尝试使用IBM i的凭据连接到MysqL数据库.
以下是有关如何在Ubuntu上连接到DB2 for i(在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] 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,1,512 AllowDataCompression = 1 LibraryView = 0 AllowUnsupportedChar = 0 ForceTranslation = 0 Trace = 0
编辑/etc/odbcinst.ini文件以包含:
[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
然后创建与PDO的连接:
$pdo = new PDO("odbc:DRIVER={iSeries Access ODBC Driver};SYSTEM=$server;PROTOCOL=TCPIP",$password);