PHP and ODBC

Using PHP to connect database via ODBC is not popular but possible. You can find the reference of built-in function of PHP and ODBC in the following url:

http://www.php.net/manual/en/ref.uodbc.php

Build a connection

<?php
//Connect to database by specify ODBC name and username and password
$conn = odbc_connect("odbc_name", "username", "password");
?>

Retrieve data from database

//Query the database
$sql = "SELECT username FROM users 
                          WHERE username='username' and password='password'";
$result = odbc_exec($conn, $sql);

//Test the query result
$user = odbc_result($result, "username");
echo("Welcome: ".$user);

Add new record

The following code show how to insert the record

//create sql insert statement
$sql = "INSERT INTO users (username, password) VALUES('Ruby', 'r0012')";
//execute query
$result = odbc_exec($conn, $sql);

Update record

The following code show how to update the record

//create sql update statement
$sql = "UPDATE users SET password='rNewPwd' WHERE username='Ruby'";
//execute query $result = odbc_exec($conn, $sql);

Delete record

The following code show how to delete the record

//create sql delete statement
$sql = "DELETE FROM users WHERE username='Ruby'";
//execute query
$result = odbc_exec($conn, $sql);

Close connection

Make the code complete by close the connection.

odbc_close($conn);