PHP with microsoft access
Moderator: General Moderators
PHP with microsoft access
I need connect PHP with a microsoft access database , how I do this ?
here ya go:
dbconnect.php
just incluce dbconnect.php in your scripts that need to connect to the database like so:
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
dbconnect.php
Code: Select all
<?php
function query_db($query) {
$db = "database";
$dbusername = "username";
$dbpassword = "password";
if (!$conn = odbc_connect($db,$dbusername,$dbpassword)) {
echo ("Cannot select ODBC database.\n");
};
return odbc_exec($conn, $query);
odbc_close($conn);
}
?>Code: Select all
<?php
include("dbconnect.php");
$query="SELECT * FROM table";
$result = query_db($query);
while (odbc_fetch_row($result)) {
$field = odbc_result($result, "field");
echo "$field<br>";
}
odbc_free_result($result);
?>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