Results 1 to 5 of 5

Thread: Converting ASP to PHP with Access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    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.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    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.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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"$passwordSQL_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();
    ?>

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width