# ADO MS Access Connection - works in ASP, but not PHP, why?



## visweb (Jan 3, 2006)

Hi folks,

I've been trying to get a connection to a MS Access DB using ADO. I can get it to work in ASP, but not in PHP. Can someone see in my code where I've gone wrong? I'm new to ADO, and I know very little about ASP. I'm more of a PHP/MySQL guy.

Here is my ASP page, that works:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& Server.MapPath("\users/target.mdb")

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from userstable", conn

do until rs.EOF
for each x in rs.fields
response.write(x.name)
response.write(" = ")
response.write(x.value & "<br/>")
next
response.write("<br/>")
rs.MoveNext
loop

rs.close
conn.close
%>


Here is my PHP which does not: (It dies with "Cannot Open with Jet")

<?
$conn = new COM("ADODB.Connection") or die("Cannot start ADO"); 

$conn->open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=". realpath("target.mdb")) or exit('Cannot open with Jet.');

$rs = $conn->Execute("SELECT username FROM userstable");

echo "<p>Below is a list of values in the target.mdb database, usertable table, username field.</p>";

// Display all the values in the records set

if (!$rs){
print ("no rs");
} else {

while (!$rs->EOF) { 
$fv = $rs->Fields("username");
echo "Value: ".$fv->value."<br>\n";
$rs->MoveNext();
} 

$rs->Close();

}
?>


Note: both the Server.MapPath in ASP and realpath in PHP give me the same result for the file location.

Thanks,

Andrew


----------



## MoralTerror (Nov 19, 2005)

Hi Andrew

Have you deleted the Access driver from the User DNS tab in control panel > administrative tools > data sources and added to System DNS tab? :4-dontkno


----------



## visweb (Jan 3, 2006)

MoralTerror, The website I am working on is located on a shared hosting server (ReadyHosting.com) and thus I don't have that kind of access.

If that was the case though, why would it work with ASP and not PHP?

Cheers,

Andrew


----------



## MoralTerror (Nov 19, 2005)

OK Andrew I'm no familar with ASP so wasn't sure.


----------



## gamerman0203 (Oct 28, 2005)

More than likely it is due to PHP being a linux server language. ASP is a windows server language which leads me to believe you are running on a windows based server since ASP is functioning fine. PHP on windows servers have to run 'in space' as they are not a nativley supported language. When doing so, some of the commands and functions have to be disabled. That may be the problem. I've run into that problem trying to run a PHPbb on a windows server that supposidly supports PHP.


----------

