PHP and MS Access
#1
Scooby Regular
Thread Starter
PHP and MS Access
Not one for asking for help but I figured somebody on here might be able to answer me this question.
Can PHP be used to pull data from a MS Access database? Using something like a Jet database connection.
Let me explain why I ask. I a few websites which currently use ASP to access a MS access database to pull information out of and need to do the same with PHP.
I dont want to go down the route of SQL as I wont be maintaining these sites and Access is easier for a client to maintain locally and then upload when required. Also these arent high hit websites. I also want to use access as some of the tables pull values out of other tables.
If this is possible can somebody point me either at a website with code I can modify or at a book which explains this.
cheers
mike
Can PHP be used to pull data from a MS Access database? Using something like a Jet database connection.
Let me explain why I ask. I a few websites which currently use ASP to access a MS access database to pull information out of and need to do the same with PHP.
I dont want to go down the route of SQL as I wont be maintaining these sites and Access is easier for a client to maintain locally and then upload when required. Also these arent high hit websites. I also want to use access as some of the tables pull values out of other tables.
If this is possible can somebody point me either at a website with code I can modify or at a book which explains this.
cheers
mike
#2
#3
Scooby Regular
Thread Starter
Its something I could do, but i'd rather not use ODBC either. In asp I use somthing like this:
<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("dbname.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT id FROM pages while id = " & request.querystring("id")
Set ddb = MyConn.Execute(SQL_query)
ddb.close
Myconn.close
set Myconn = nothing
%>
I just want something really cheap and dirty to do the same in php.
Basically the site this will be running on will need to get the id of an item from the URL, ie: page.php?id=100. The database then looks up item 100 in the db and loads its contents, where its displayed.
mike
<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("dbname.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT id FROM pages while id = " & request.querystring("id")
Set ddb = MyConn.Execute(SQL_query)
ddb.close
Myconn.close
set Myconn = nothing
%>
I just want something really cheap and dirty to do the same in php.
Basically the site this will be running on will need to get the id of an item from the URL, ie: page.php?id=100. The database then looks up item 100 in the db and loads its contents, where its displayed.
mike
#4
Scooby Regular
Thread Starter
This works on a windows server but not Unix?!
<?
$db_connection = new COM("ADODB.Connection");
$db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("somedb.mdb") ." ;DefaultDir=". realpath("../");
$db_connection->open($db_connstr);
$rs = $db_connection->execute("SELECT * FROM pages");
$rs_fld0 = $rs->Fields(0);
$rs_fld1 = $rs->Fields(1);
$rs_fld2 = $rs->Fields(2);
while (!$rs->EOF) {
/* do some stuff with the results to make it look nice on screen */
/* but as an example... */
print "$rs_fld0->value $rs_fld1->value $rs_fld2->value\n<br>";
$rs->MoveNext(); /* updates fields! */
}
$rs->Close();
$db_connection->Close();
?>
<?
$db_connection = new COM("ADODB.Connection");
$db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("somedb.mdb") ." ;DefaultDir=". realpath("../");
$db_connection->open($db_connstr);
$rs = $db_connection->execute("SELECT * FROM pages");
$rs_fld0 = $rs->Fields(0);
$rs_fld1 = $rs->Fields(1);
$rs_fld2 = $rs->Fields(2);
while (!$rs->EOF) {
/* do some stuff with the results to make it look nice on screen */
/* but as an example... */
print "$rs_fld0->value $rs_fld1->value $rs_fld2->value\n<br>";
$rs->MoveNext(); /* updates fields! */
}
$rs->Close();
$db_connection->Close();
?>
#5
Scooby Regular
Join Date: Sep 1999
Location: Bedfordshire
Posts: 4,037
Likes: 0
Received 0 Likes
on
0 Posts
You wont be able to use an access mdb on *nix systems its windows only. If you're hosting on *nix then with php you really need to be looking at mysql which is open source, also get hold of phpmyadmin which is a web based tool for administering mysql databases.
Gary
Gary
#6
Scooby Regular
Thread Starter
Yeah! i've asked my isp a few questions about this and am awaiting there reply. I dont want to go down the sql route as its extra work that I could do without! Plus I have to provide the client with a means of updating this. it would be much easier to say heres a database, off you go! I think i'll be using Perl and a CSV database if they persist in using there current host.
Thread
Thread Starter
Forum
Replies
Last Post