How to connect MS Access DB (.mdb) using PHP

Discussion in 'PHP' started by KingCobra, May 31, 2012.

  1. #1
    Dear friends,

    I am in a problem.

    I need to connect a ms access db (example: mydb.mdb) using PHP that is (database) located in my another pc.
    I made a share folder on my second pc and place the database there. it looks like (C:/share/mydb.mdb)
    It can be accessed through local ip too like (\\192.168.2.12\share\mydb.mdb)

    I also made map drive in my pc-1 (php page running from here) for that shared folder.
    T looks like now (Z:/mydb.mdb)

    But I can't connect anyway using php. If place the database in my local pc then I can easily connect to the db using DSN or without DSN.

    Here is the code that is work for db connect that is located in same pc.

    
    <?php
    
      //Collect form data and assign to scalar variables
    
      $name = $_POST["name"];
    
      //Establish a connection to the Database (use any one)
    
      $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=E:\mydb.mdb','','123');  // Without DSN
      //$conn = odbc_connect('MyDatabase','','1234');  // using DNS
    
      //SQL Statement
    
      $sql = "INSERT INTO data (name) VALUES ('$name')"; 		 
    		
    	
      //Execute SQL Statement and store results as a recordset
    	
      $rs = odbc_exec($conn,$sql);
    
      if (!$rs){
          exit("Error in SQL");
      }
    
      odbc_close($conn);
      echo "ok";
    
    ?>
    
    PHP:
    Please help me how can i connect shared/networked/map drive database.

    Thanks
     
    KingCobra, May 31, 2012 IP
  2. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #2
    Maybe DBQ=Z:\mydb.mdb instead of DBQ=E:\mydb.mdb
     
    kbduvall, May 31, 2012 IP