Open In App

How to connect ODBC Database with PHP?

The Microsoft Open Database Connectivity (ODBC) is a C application programming language interface. So the applications can access data from different database management systems.  The designers of ODBC aimed to make it independent of database systems and operating systems. In this article, we are using the Microsoft Access database to establish a connection.

Requirements: If ODBC Drivers are installed or the old version is installed, then update to the latest version or install the driver first 



Steps to follow for ODBC connection to an MS Access Database:



                               

Example: The following example demonstrates the simple connection script.




<!DOCTYPE html>
<html>
 
<body>
 <?php
   //Storing DSN(Data Source Name created)
  $dsn="raj";
  $user="root";
  $password="";
    
   //storing connection id in $conn
  $conn=odbc_connect($dsn,$user, $password);
 
  //Checking connection id or reference
  if (!$conn)
   {
   echo (die(odbc_error()));
   }
   else
  {
      echo "Connection Successful !";
  }
  //Resource releasing
  odbc_close($conn);
  ?>
 
</body>
</html>

 Below output will be shown on the browser

Output: 

Connection Successful !

 

Article Tags :