ODBC connection With MS Access DataBase in PHP

<?php
//odbc conncetion with MS Access

// create database in ms access 
/* control pannel => Administrative Tools =>  Data Sources (ODBC) =>System DSN  => add => Microsoft Access Driver =>Finish

Create => 'name of database and select location' // open database and create table  */

// Configuration Variables **/ 
define('DB_NAME''db1.mdb');  // db1.mdb  database name 
define('DB_USER'''); 
define('DB_PASSWORD'''); 
$dbq=dirname($_SERVER['SCRIPT_FILENAME']). '/'.DB_NAME // database location 
   

 if  (!file_exists($dbq)) {  // if database not Exist
        die( 
"
Database Not Found."
); 
    } 

$conn odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$dbqDB_USERDB_PASSWORD"SQL_CUR_USE_ODBC"); 

if (!
$conn){exit("Connection Failed: " $conn);} 


  
odbc_exec($conn,"insert into table1(id , name)values(1,'ffff')");  // insert query   // table1 = table name

  $sql="SELECT * FROM table1";$rs=odbc_exec($conn,$sql); 

if (!
$rs){exit("Error in SQL");}
echo 
"

"

;
echo 
"

Name

";
echo 
"

Name

";
while (
odbc_fetch_row($rs))
  {
  
$compname=odbc_result($rs,"name");
  
$conname=odbc_result($rs,"name");
  echo 
"

$compname

"

;
  echo 
"

$conname

";
  }
  
//odbc_exec($conn,"delete from table1"); // delete query , delete all record

odbc_close($conn);
echo 
"";?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s