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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…