as400

setup odbc to AS400 (iSeries) on Debian 9 and PHP

apt-get install unixodbc unixodbc-dev
dpkg -i ibm-iaccess-1.1.0.11-1.0.amd64.deb
apt-get install php7.0-odbc
odbcinst -i -d -f /opt/ibm/iaccess/unixodbcregistration
nano /etc/odbc.ini

On the ini file type:

[MyDSN]
Description             = Company DB
Driver                  = IBM i Access ODBC Driver
System                  = myserver.mycompany.local
UserID                  = username
Password                = password
Naming                  = 0
DefaultLibraries        = mylibrary
Database                =
ConnectionType          = 1 (0=read/write; 1=readonly)
BlockFetch              = 1
BlockSizeKB             = 512

[MyDSN2]
Description             = Company DB2
Driver                  = IBM i Access ODBC Driver
System                  = myserver2.mycompany.local
UserID                  = username
Password                = password
Naming                  = 0
DefaultLibraries        = mylibrary
Database                =
ConnectionType          = 1
BlockFetch              = 1
BlockSizeKB             = 512

.....

On my php file with PDO:

$pdo = new PDO("odbc:MyDSN");
$stmt = $pdo->query("SELECT * FROM mytable");
while ($row = $stmt->fetch()) {
        print_r($row);
}

Quering AS400 From Powershell via ODBC

Connection String for quering an odbc AS400 database via powershell:


$query = "SELECT * FROM my_table"
$conn = New-Object System.Data.Odbc.OdbcConnection
$conn.ConnectionString = "Driver={iSeries Access ODBC Driver};System=my-as400-server;Uid=User;Pwd=Password;"
$conn.Open()
$cmd = New-Object System.Data.Odbc.OdbcCommand($query, $conn)
$cmd.CommandTimeout = 15
$ds = New-Object system.Data.DataSet
$da = New-Object system.Data.odbc.odbcDataAdapter($cmd)

[void]$da.fill($ds)
$conn.close()

$result = $ds.tables[0]


foreach ($Row in $ds.Tables[0].Rows) {
write-Output "$($Row.field1)"
write-Output "$($Row.field2)"
}