title: Connecting to an IBM AS/400 DB2 Database
body: <p>I'm trying to connect to a client's IBM AS/400 DB2 Database from an Ubuntu Server using PHP's <strong>ODBC Driver</strong>. I have the <strong>unixODBC</strong> installed as well. My <strong>odbcinst.ini</strong> looks like this:</p>
  
  <pre><code>[IBM DB2 ODBC DRIVER]
  Description = ODBC 5.1 Driver for Database
  Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
  FileUsage = 1
  </code></pre>
  
  <p>And my <strong>odbc.ini</strong> looks like this:</p>
  
  <pre><code>[IBM DB2 ODBC DRIVER]
  Driver = IBM DB2 ODBC DRIVER
  Description = ODBC 5.1 Driver DSN
  </code></pre>
  
  <p>Now, my code to connect is:</p>
  
  <pre><code>$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!';
  </code></pre>
  
  <p>The error I get is this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I tried using the PDO ODBC Driver also. This is the error I get:</p>
  
  <pre><code>$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-&gt;__construct('odbc:DRIVER={IB...') #1 {main} thrown in /var/www/test_file.php
  </code></pre>
  
  <p>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 <strong>Access Denied for user</strong>. It doesn't seem to be the case. There might be something else that's wrong. </p>
  
  <p>Thank you for your help. I hope I made the problem very clear. Thanks!  </p>