Page 1 of 1

PHP with microsoft access

Posted: Wed Jul 17, 2002 2:49 pm
by gsigal
I need connect PHP with a microsoft access database , how I do this ?

Posted: Wed Jul 17, 2002 3:06 pm
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.

Posted: Wed Jul 17, 2002 9:23 pm
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 :)