0
votes

I'm trying to use jQuery-jTable to list data from a MS-Access database through PHP. I want to change the sample provided by jTable.org : http://www.jtable.org/downloads/jTable-PHP-Samples.zip

<?php

try { //Open database connection $db_connection = odbc_connect("Persist Security Info=False;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\websiagh\books\54.mdb", "ADODB.Connection", "password", SQL_CUR_USE_ODBC) or die('Cannot connect to 54');

//Getting records (listAction)
if($_GET["action"] == "list")
{
    //Get records from database
$query = 'SELECT * FROM asnad WHERE (sanadno Between 10 AND 20 )';
$result = odbc_exec($db_connection , $query );


    //Add all records to an array
    $rows = array();
    while( $row = odbc_fetch_array( $result ) )
    {
        $rows[] = $row;
    }

    //Return result to jTable
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['Records'] = $rows;
    print json_encode($jTableResult);
}

...

The rest of the code is not changed. The code ( query execution and fetching data using odbc ) works well when not using jTable. However when using it in the code as above , I get this error : An error occured while communicating to the server. But when I export the data from MS-Access to mysql, there is no problem at all.

1

1 Answers

0
votes

For me your query execution and fetching data using odbc didn't work. This may be depending on the Window OS and the version of PHP.

The following however did work with jTables (credits to w3schools.com):

  1. Open the Administrative Tools icon in your Control Panel.
  2. Double-click on the Data Sources (ODBC) icon inside.
  3. Choose the System DSN tab.
  4. Click on Add in the System DSN tab.
  5. Select the Microsoft Access Driver. Click Finish.
  6. In the next screen, click Select to locate the database. Give the database a Data Source Name (DSN).
  7. Click OK.

After, to create a connection use the following (assuming your database is called 54.mdb):

$db_connection=odbc_connect('54','','');
if (!$db_connection) {
  exit("Connection Failed: " . $db_connection);
} 

The rest of the code remains as is.

Hope this helps.