Next Previous Contents

20. Appendix J phpDBTest.php3 Example

Submitted by: Joe Thong [email protected] Site URL: http://phpdb.linuxbox.com

Description: A PHP database wrapper for various database servers with a powerful Recordset for result data manipulation. Database results are flushed automatically by phpDB.

To get this file, in the web-browser, save this file as 'Text' type as phpDB-mssql.lib


<html>
< head>
        < title>Untitled< /title>
< /head>

< body>
<?php
        // Assumed this file is placed in the same directory with phpDB.inc
        include("phpDB.inc");   
        $db = new phpDB();
        $db->pconnect("hostName", "userName", "passWord", "databaseName") or die ("Can't connect to database server or select database");
        $rs = $db->execute("SELECT * FROM Items");
        $numOfRows = $rs->getNumOfRows();
        echo "Number of Rows: $numOfRows";      

        $rs->firstRow(); // optional, but recommended
        while (!$rs->EOF) {
                // Fields collection accessible as associative arrays too
                echo "<br>" . $rs->fields[0];
                $rs->nextRow(); // NOTE: nextRow() is placed at below
        }

        $rs->close();           
        $db->close();   // optional
?>
< /body>
< /html>


Next Previous Contents