title: howto connect to as400 with PHP
body: <p>I am trying to connect my AS400 with V5R3 with PHP using this code :</p>
  
  <pre><code>&lt;?php
  $server="Driver={Client Access ODBC Driver (32-bit)};System=xxx.xxx.xxx.xxx;
  Uid=user;Pwd=password;"; #the name of the iSeries
  $user="user"; #a valid username that will connect to the DB
  $pass="password"; #a password for the username
  
  $conn=odbc_connect($server,$user,$pass); #you may have to remove quotes
  
  #Check Connection
  if ($conn == false) {
  echo "Not able to connect to database...&lt;br&gt;";
  }
  
  #Query the Database into a result set - 
  $result=odbc_exec($conn,"SELECT * FROM LIBRARY.V5TDOC0L WHERE T§DTDO = 20120319");
  
  if (!$result)
    {exit("Error in SQL");}
  echo "&lt;table&gt;&lt;tr&gt;";
  echo "&lt;th&gt;T§NDOC&lt;/th&gt;";
  echo "&lt;th&gt;T§DTDO&lt;/th&gt;&lt;/tr&gt;";
  while (odbc_fetch_row($result))
    {
    $ndoc=odbc_result($result,2);
    $dtdo=odbc_result($result,3);
    echo "&lt;tr&gt;&lt;td&gt;$ndoc&lt;/td&gt;";
    echo "&lt;td&gt;$dtdo&lt;/td&gt;&lt;/tr&gt;";
    }
  echo "&lt;/table&gt;";
  
  #close the connection
  odbc_close($conn);
  ?&gt;
  </code></pre>
  
  <p>I got this error :</p>
  
  <p>Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][Programma di controllo ODBC di System i Access][DB2 per i5/OS]SQL0104 - Token � not valid. Token valid: &lt; > = &lt;> &lt;= !&lt; !> != >= �&lt; �> �= IN IS NOT LIKE BETWEEN., SQL state 37000 in SQLExecDirect in F:\xampp\htdocs\php-as400\php-as400.php on line 25
  Error in SQL</p>
  
  <p>Removing from the statement SELECT the <code>WHERE T§DTDO = 20120319</code>, I have it running and listing the elements I want with a warning.</p>
  
  <pre><code>Fatal error: Maximum execution time of 30 seconds exceeded in F:\xampp\htdocs\php-as400\php-as400.php on line 30
  T§NDOC  T§DTDO
  C008931 19941102
  P005027 19950214
  P005031 19950320
  P005055 19950612
  P005062 19950904
  P005065 19950920
  P005082 19951218
  P005157 19970102
  P005186 19970428
  P005187 19970429
  P005190 19970520
  I009353 19970721
  P005257 19980217 
  </code></pre>
  
  <p>Line 30 is :</p>
  
  <pre><code>while (odbc_fetch_row($result))
  </code></pre>
  
  <p>I believe the problem is the character § as I found looking in internet (<a href="https://bugs.php.net/bug.php?id=47133" rel="nofollow">https://bugs.php.net/bug.php?id=47133</a>), but I don't know how to solve it.</p>