|
-
Mar 2nd, 2009, 02:13 PM
#1
Thread Starter
Addicted Member
Converting ASP to PHP with Access
I have a web site written in ASP utilizing Access databases and I want to convert it to PHP. My web server is a Windows 2000 server using IIS 5, and I installed PHP 5.1.2.
Here is sample code from a page that reads data from one of the databases and displays it in a table. How can I convert this to PHP?
Code:
<%
set myconn = server.createobject("adodb.connection")
dbpath = server.mappath("databases/Stables.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbpath & ";"
set result = server.createobject("adodb.recordset")
sql = "SELECT * FROM Stables ORDER BY Stable_Name"
set result = myconn.execute(sql)
response.write("<p>")
response.write("<table border=0 width='40%' cellpadding=3 cellspacing=0 align=center class=tbl1bgColor>")
response.write("<tr>")
response.write("<td width='55%' class=searchRHeadings align=left nowrap>")
response.write("<p align=center><strong>Stable</strong>")
response.write("<td width='10%' class=searchRHeadings align=center nowrap>")
response.write("<p align=center><strong>Silks</strong>")
response.write("<td width='25%' class=searchRHeadings align=left nowrap>")
response.write("<p align=center><strong>Country</strong>")
response.write("</tr><tr>")
z=1
while not result.EOF
if (z mod 2=0) then
className="tdResultsRow1 "
else
className="tdResultsRow2 "
end if
If result("Web") then
response.write("<td width='55%' class='" & classname & "' align=left nowrap><a href=" & result("Site") & ">" & result("Stable_Name"))
Else
response.write("<td width='55%' class='" & classname & "' align=left nowrap>" & result("Stable_Name"))
End IF
If result("Silks") then
response.write("<td width='10%' class='" & classname & "' align=right nowrap><img src='images/Silks/" & result("Stable_ID") & ".gif'>")
Else
response.write("<td width='10%' class='" & classname & "' align=right nowrap>")
End if
response.write("<td width='25%' class='" & classname & "' align=left nowrap>" & result("Location"))
response.write("</td>")
result.movenext()
response.write("</tr>")
z=z+1
wend
response.write("</table>")
%>
I can make this code work in php using MySQL, but I can't wrap my head around how to get PHP to talk to the Access database.
-
Mar 2nd, 2009, 04:30 PM
#2
Re: Converting ASP to PHP with Access
to use Access with PHP, you'll need to use the ODBC functions. to get started, I'd check out odbc_connect() or the list of ODBC functions.
-
Mar 5th, 2009, 09:58 AM
#3
Thread Starter
Addicted Member
Re: Converting ASP to PHP with Access
I've looked those over but they didn't help very much. Isn't there somewhere a simple tutorial on how to connect PHP5 to an Access Database on a Windows system without using DSN? I've been searching all over the web without luck.
-
Mar 5th, 2009, 03:39 PM
#4
Re: Converting ASP to PHP with Access
well, Access is not really supported much with PHP except using the ODBC functions. with limited searching, I found no real tutorials. I have -very- little experience dealing with connection strings, databases in any BASIC languages, and I've never needed to use ODBC in PHP. these are two examples I found in the comments of odbc_connect() that seem to mimic the way that you're connecting in the ASP script:
PHP Code:
<?php //using odbc_connect $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)}; DBQ=$database", "ADODB.Connection", $password, SQL_CUR_USE_ODBC); ?>
<?php //not using odbc_connect $db_connection = new COM("ADODB.Connection");
$db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../databases/database.mdb") ." ;DefaultDir=". realpath("../databases"); $db_connection->open($db_connstr); $rs = $db_connection->execute("SELECT * FROM Table"); $rs_fld0 = $rs->Fields(0); $rs_fld1 = $rs->Fields(1); while (!$rs->EOF) { print "$rs_fld0->value $rs_fld1->value\n"; $rs->MoveNext(); /* updates fields! */ } $rs->Close(); $db_connection->Close(); ?>
-
Mar 12th, 2009, 07:09 PM
#5
Re: Converting ASP to PHP with Access
I would not recommend the use of Access as a back end to a web site. There are certain limitations which can slow things down, corrupt the databse or cuase the site to stop functioning.
Off the top of my head these are:
- Poor handling of simultanious connections.
- 2GB size limit on database files.
- Limited sotred procedure and no trnasaction support.
If you must continue then you will need to use ODBC. I would recommend the PDO_ODBC Driver.
http://php.oregonstate.edu/manual/en/ref.pdo-odbc.php
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|