Page 1 of 1

Connecting to MS Access DB

Posted: Tue Feb 21, 2006 5:19 am
by Dark_AngeL
Hi

I am trying to create a connection to my Acess DB warehouse which has 1 table Users and Autonumber username password as fields ...


This is the code i wrote .. but i feel that i am missing something can someone show me the right path please

Code: Select all

<?
$conn=odbc_connect('warehouse','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql="SELECT username FROM Users";
$sql="SELECT password FROM Users";
$rs=odbc_exec($conn,$sql);
if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>username</th>";
echo "<th>password</th></tr>";
while (odbc_fetch_row($rs))
{
  $username=odbc_result($rs,"username");
  $password=odbc_result($rs,"password");
  echo "<tr><td>$username</td>";
  echo "<td>$password</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>

Posted: Tue Feb 21, 2006 5:32 am
by Maugrim_The_Reaper
http://php.mirrors.esat.net/manual/en/f ... onnect.php

You need to have either a DSN for the Access data file, or else use the path to the file on your system to create a DSN-less connection. For example:

Code: Select all

odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=
C:\Access_Files\_database\dbname.mdb", "", "")
Edit: The above is all one line - i broke it in 2 since the forum's PHP divs are not adding a side scoller....

I'm not sure whether the filesystem \ characters should \\ instead - but try it out with the path to your own access file... This is for a DSN-less connection (no ODBC setup required). You can run a google search for more complex examples using Access.

Posted: Tue Feb 21, 2006 5:51 am
by Dark_AngeL
Thank you

But when i did so and clicked on submit i got this page instead of going to the menu page!


The page cannot be displayed
The page you are looking for cannot be displayed because the page address is incorrect.

--------------------------------------------------------------------------------

Please try the following:

If you typed the page address in the Address bar, check that it is entered correctly.

Open the localhost home page and then look for links to the information you want.
HTTP 405 - Resource not allowed
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

More information:
Microsoft Support

Posted: Tue Feb 21, 2006 5:54 am
by Maugrim_The_Reaper
Try:
http://php.net/odbc_connect

Sorry gave you a local Irish mirror ;)