PHP Database Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anandakumarpc
    New Member
    • Nov 2005
    • 3

    PHP Database Programming

    I'm just learning PHP. I would like to know if database programming in PHP can be done using MS-Access. Can any one help me with complete example codes please.
  • Niheel
    Recognized Expert Moderator Top Contributor
    • Jul 2005
    • 2432

    #2
    Here is sample code on a connection. Tested on WinXP, works fine.

    [CODE=php]
    <?
    // url to database file
    $db = 'C:\\Program Files\\Microsof t Office\\Office\ \Samples\\North wind.mdb';

    // adodb connection
    $conn = new COM('ADODB.Conn ection');
    $conn->Open("Provider =Microsoft.Jet. OLEDB.4.0; Data Source=$db");

    // sql code
    $sql = 'SELECT ProductName, QuantityPerUnit , UnitPrice
    FROM Products
    ORDER BY ProductName';
    $rs = $conn->Execute($sql );

    // html
    ?>
    <table>
    <tr>
    <th>Product Name</th>
    <th>Quantity Per Unit</th>
    <th>Unit Price</th>
    </tr>
    <? while (!$rs->EOF): ?>
    <tr>
    <td><?= $rs->Fields['ProductName']->Value ?></td>
    <td><?= $rs->Fields['QuantityPerUni t']->Value ?></td>
    <td><?= $rs->Fields['UnitPrice']->Value ?></td>
    </tr>
    <? $rs->MoveNext() ?>
    <? endwhile ?>
    </table>
    <?
    $rs->Close();
    $conn->Close();
    ?>
    [/CODE]
    niheel @ bytes

    Comment

    Working...