Home Tutorial Php Sql Php Sql ODBC

 
 

Share on Google+Share on Google+
Php Sql ODBC
Posted on: December 10, 2010 at 12:00 AM
Advertisement
This example illustrates how to create a ODBC Connection for php application.

Php Sql ODBC

 This example illustrates how to create a ODBC Connection for php application.

With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available.

Here is how to create an ODBC connection to a MS Access Database: 

  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.
  7. Give the database a Data Source Name (DSN).
  8. Click OK.

Note that this configuration has to be done on the computer where your web site is located. If you are running Internet Information Server (IIS) on your own computer, the instructions above will work, but if your web site is located on a remote server, you have to have physical access to that server, or ask your web host to to set up a DSN for you to use.

 

Source Code of sqlodbc.php 

<html>
<body>
  <?php
    $conn=odbc_connect('myodbc','','');
    if (!$conn){
      exit("Connection Failed: " . $conn);
    }
    
    $sql="SELECT * FROM emp";
    $rs=odbc_exec($conn,$sql);

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

    echo "<table><tr>";
    echo "<th>Emp_ID</th>";
    echo "<th>Name</th></tr>";

    while (odbc_fetch_row($rs)){
      $id=odbc_result($rs,"id");
      $name=odbc_result($rs,"name");
      echo "<tr><td>$id</td>";
      echo "<td>$name</td></tr>";
    }
    odbc_close($conn);
    echo "</table>";
  ?>

</body>
</html>

Download Source Code

 

 

Output:

Advertisement

Related Tags for Php Sql ODBC:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 10, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com