Play-Asia.com - Buy Video Games for Consoles and PC - From Japan, Korea and other Regions!

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);
 
 
Visitor Review Write a review
No visitor review for this page yet
Write a review
Rating:
Text:
Name:
Email:
(optional)
 
Code:
 

Search:
Shopping Store Online
Clothes (25)
Gift shop (69)
Hand-made (27)
Luxuries (47)
Others (42)
Programming Tutorial
ASP (14)
CSharp (29)
HTML (10)
JavaScript (6)
Photoshop (9)
PHP
Arrays
Object-Oriented Programming
PHP and COM
PHP and MySQL
PHP and ODBC
PHP Calendar and Date Picker Calendar component
Entertainment
Anime (6)
E-Cards (12)
Games (20)
Music (7)