Connecting PHP to MS Access DB on linux server

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
User avatar
planketa
New php-forum User
New php-forum User
Posts: 152
Joined: Mon Mar 08, 2004 12:29 am
Location: Philippines

Thu Dec 07, 2006 12:45 am

Hi guys

how can we connect php to ms access if the php is on a linux server and the access db is on a windows server?

i know we can always use mysql but the db in access is already in use and we have to maintain the file format of the db.

thanks
PHP Rules

User avatar
gesf
Moderator
Moderator
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Thu Dec 07, 2006 2:28 am

Luckily PHP has ODBC (Open Database Connectivity) compatibility with MSAccess :)
You need to create a Data Sourse for that. Please follow this article.
Sincerely,
Gonçalo "gesf" Fontoura

gesf.org | sessionstart.com | urlms.com

User avatar
planketa
New php-forum User
New php-forum User
Posts: 152
Joined: Mon Mar 08, 2004 12:29 am
Location: Philippines

Sun Dec 10, 2006 7:26 pm

How about dsn less connection? if the access file and the php page is on the same location (folder) in unix system how do we get info from the access file?

thanks again.
PHP Rules

User avatar
gesf
Moderator
Moderator
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Tue Dec 12, 2006 8:35 am

Not sure if i got the point, but... after setting up your ODBC source, you just need to run your query (example):

Code: Select all

<?php

require_once 'odbc.php';

// You know what this next function is. The system just doesn't allow me to post the correct name
$query = odbc_ex3c($odbc, "SELECT * FROM users") or die (odbc_errormsg());
while($row = odbc_fetch_array($query)) {
    print 'User Name: ' . $row['user_name'] . '<br />';
    print 'User E-mail Address: ' . $row['user_email'] . '<br />';
    print '<hr />';
}
odbc_close($odbc);

?>
Sincerely,
Gonçalo "gesf" Fontoura

gesf.org | sessionstart.com | urlms.com

Post Reply