# Miscellaneous > Database Programming >  PHP ODBC Connection to Paradox DB

## jhannley

Hi,

I have a paradox DB that I created a DSN ODBC connection with in Windows 2008. I also have apache running on the same box.

I am trying to connect to the db via ODBC and PHP but I have hit some serious road blocks.

My PHP script, parses the DB and extracts the information to a MYSQL database every 10 seconds.  The issue is that it dies, not when I connect to the ODBC datasource but when I query against it!  But it's not consistent.... for example:

There are times when my script runs without any issues!
There are times when it dies completely barfing error code: S0002 - essentially telling me it can't find the table.
There are times when it consistently works one iteration and then dies every second iteration...

I can view this database in EXCEL, 100% at all times via ODBC!

Does anyone have any suggestions or thoughts onto what's happening here?

Thanks,  
Jeremiah



```

  include "DatabaseHandler.php";
  
  //for each file in folder that has an extension .db
  //parse and upload to database
  //remove/delete file when finished

  ini_set('memory_limit', '64M');
  //set_time_limit(300);           
  
  echo "Start@(".date('h:i:s').")</br>";
  ExtractFromParadoxInsertIntoSQL($ParadoxDatabase);
  
  /*
  * @desc Grabs events from paradox db and dumps them into a SQL file
  */
  function ExtractFromParadoxInsertIntoSQL($db){

   // include_once "DatabaseHandler.php";   
    define ('PkMessageInfo', 1);
    define ('DateTime', 6);
    define ('MessageType', 7);
    define ('Message', 8);
    define ('Message1', 9);
    define ('Message2', 10);
    define ('ObjectDescription1', 24);
    define ('Description11', 25);
    define ('Description12', 26);
    define ('ObjectDescription2', 28);
    define ('Description21', 29);
    define ('Description22', 30);
    define ('ObjectDescription3', 32);
    define ('Description31', 33);
    define ('Description32', 34);

    try{
                                      
      //copy file
      copy("C:/Program Files/KT/Data/messageinfo.db","c:/xampp/htdocs/myprogram/paradox.db");
      $connection = odbc_connect("paradox.DB","",""); 
      
     $from = Date('Y-m-d H:i:s', strtotime('-5 hours')); //today minus 5 hours 
      
      $strQuerySQL = "SELECT * FROM messageinfo
                      WHERE datetime >{ts '$from'}
                      AND (messagetype=65 or messagetype=72)
                      ";


/*
*  THE FOLLOWING LINE OF CODE SEEMS TO NOT WORK ALL THE TIME :mad::mad::mad:
*/
      $result = odbc_exec($connection, $strQuerySQL) or die(odbc_errormsg($connection));


      
 
     $iCount = 0;  
      while( odbc_fetch_row( $result ) ) {
        $intPKMessageInfo = odbc_result($result, PkMessageInfo);
        $dateDateTime = odbc_result($result, DateTime);
        $intMessageType = odbc_result($result, MessageType);
        $intMessage = odbc_result($result, Message);
        $strMessage1 = odbc_result($result, Message1);
        $strMessage2 = odbc_result($result, Message2);
        $intObjectDescription1 = odbc_result($result, ObjectDescription1);
        $strDescription11 = odbc_result($result, Description11);
        $strDescription12 = odbc_result($result, Description12);
        $intObjectDescription2 = odbc_result($result, ObjectDescription2);
        $strDescription21 = odbc_result($result, Description21);
        $strDescription22 = odbc_result($result, Description22);
        $intObjectDescription3 = odbc_result($result, ObjectDescription3);
        $strDescription31 = odbc_result($result, Description31);
        $strDescription32 = odbc_result($result, Description32);
        
        
         echo "<tr>";
         echo "<td>$intPKMessageInfo</td>";
         echo "<td>$dateDateTime</td>";
         echo "<td>$intMessageType</td>";
         echo "<td>$intMessage</td>";
         echo "<td>$strMessage1</td>";
         echo "<td>$strMessage2</td>";
         echo "<td>$intObjectDescription1</td>";
         echo "<td>$strDescription11</td>";
         echo "<td>$strDescription12</td>";
         echo "<td>$intObjectDescription2</td>";
         echo "<td>$strDescription21</td>";
         echo "<td>$strDescription22</td>";
         echo "<td>$intObjectDescription3</td>";
         echo "<td>$strDescription31</td>";
         echo "<td>$strDescription32</td>";
         echo "</tr>";
        
       
        $iCount++;
                            
      }
      echo "</table>";
     
     echo "Number of events crunched:$iCount</br>";
     echo "Done@(" . date('h:i:s').")";
     odbc_close($connection);
    } catch (Exception $e) {
        print("ExtractFromParadoxInsertIntoSQL: ");
        var_dump($e->getMessage());
        $lf = new logfile();
        $lf->write(var_dump($e->getMessage()) . "\r\n");
    }
  }
      
  }
```

----------


## Frank

This is an ASP forum. You ned to go to the PhP forum. If you are still using ODBC, you are several generation behind. Check out www.aspdb.com to see how wasy it is to generate a Web DB application.

Frank

----------

