PHP with microsoft access

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gsigal
Forum Newbie
Posts: 1
Joined: Wed Jul 17, 2002 2:49 pm
Location: Argentina
Contact:

PHP with microsoft access

Post by gsigal »

I need connect PHP with a microsoft access database , how I do this ?
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

I'd say you should use a odbc connection. You can trhough this talk sql with the access databas.

Read more about odbc in the php manual or look for a tutorial.
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

here ya go:

dbconnect.php

Code: Select all

<?php

function query_db($query) &#123;
     $db = "database";
     $dbusername = "username";
     $dbpassword = "password";
	if (!$conn = odbc_connect($db,$dbusername,$dbpassword)) &#123;
			echo ("Cannot select ODBC database.\n");
	&#125;;
	return odbc_exec($conn, $query);
	odbc_close($conn);
&#125;

?>
just incluce dbconnect.php in your scripts that need to connect to the database like so:

Code: Select all

<?php

include("dbconnect.php");
$query="SELECT * FROM table";
$result = query_db($query);
while (odbc_fetch_row($result)) &#123;
     $field = odbc_result($result, "field");
     echo "$field<br>";
&#125;
odbc_free_result($result);

?>
remember, you have to setup a SYSTEM DSN for php to be able to access the database.

Im on windows XP so here's where u go:
Control Panel -> Administrative Tools -> Data Sources (ODBC) -> System DSN tab -> Click on ADD

hope it helps :)
Post Reply