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
$conn = odbc_connect("odbc_name", "username", "password");
?>
Retrieve data from database
$sql = "SELECT username FROM users
WHERE username='username' and password='password'";
$result = odbc_exec($conn, $sql);
$user = odbc_result($result, "username");
echo("Welcome: ".$user);
Add new record
The following code show how to insert the record
$sql = "INSERT INTO users (username, password) VALUES('Ruby', 'r0012')";
$result = odbc_exec($conn, $sql);
Update record
The following code show how to update the record
$sql = "UPDATE users SET password='rNewPwd' WHERE username='Ruby'";
$result = odbc_exec($conn, $sql);
Delete record
The following code show how to delete the record
$sql = "DELETE FROM users WHERE username='Ruby'";
$result = odbc_exec($conn, $sql);
Close connection
Make the code complete by close the connection.
odbc_close($conn); |