芝麻web文件管理V1.00
编辑当前文件:/home/strato/chroot/opt/RZphp80/includes/DB/test/ado_test.php
"ado", 'dbsyntax' => "access", // or mssql or odbc 'username' => "", 'username' => "Admin", // or sa 'password' => "", 'database' => "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Programs\\Microsoft Office\\Office\\Samples\\Nordwind.mdb;Persist Security Info=False" // 'database' => "Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Northwind;" ); $conn = DB::connect($dsn, TRUE); assertObject($conn); // select your fetchmode to test (DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT)19.04.2002 $conn->setFetchMode(DB_FETCHMODE_ASSOC); printH2("Fetch row functions"); $sql = "SELECT TOP 10 * FROM Customers"; $rs = $conn->query($sql); $i = 1; assertObject($rs); while ($row = $rs->fetchRow()) { printLoop($row, $i); } printHR(); $sql = "SELECT TOP 5 * FROM Employees"; $rs = $conn->query($sql); $i = 1; assertObject($rs); while ($rs->fetchInto($row)) { printLoop($row, $i); } printHR(); $sql = "SELECT TOP 10 * FROM Orders"; $rs = $conn->query($sql); $i = 1; assertObject($rs); while ($row = $rs->FetchRow()) { printLoop($row, $i); } printHR(); // next examples taken from http://vulcanonet.com/soft/?pack=pear_tut#ss3.3.5 printH2("Fetch rows by number"); $i = 1; $sql = "SELECT * FROM Employees"; $from = 1; $res_per_page = 6; $to = $from + $res_per_page; $fetchmode = DB_FETCHMODE_ASSOC; //(DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT) $rs = $conn->query($sql); assertObject($rs); foreach (range($from, $to) as $rownum) { if (!$row = $rs->fetchRow($fetchmode, $rownum)) { break; } printLoop($row, $i); } printHR(); printH2("Quick data retrieving"); $sql = "SELECT TOP 5 * FROM Suppliers"; echo "
getOne
\n"; $rs = $conn->getOne($sql); assertObject($rs); echo var_dump($rs); printHR(); echo "
getRow
\n"; $row = $conn->getRow($sql); assertObject($row); echo var_dump($row); printHR(); $sql = "SELECT TOP 10 CompanyName FROM Suppliers"; echo "
getCol
\n"; $row = $conn->getCol($sql); assertObject($row); echo var_dump($row); printHR(); $sql = "SELECT TOP 5 * FROM Suppliers"; echo "
getAssoc
\n"; $rs = $conn->getAssoc($sql); assertObject($rs); echo var_dump($rs); printHR(); echo "
getAll
\n"; $rs = $conn->getAll($sql); assertObject($rs); echo var_dump($rs); printHR(); printH2("Infos from query result"); $rs = $conn->query($sql); assertObject($rs); echo "
numRows
\n"; echo $rs->numRows(); assertObject($rs); printBR(); echo "
numCols
\n"; echo $rs->numCols(); assertObject($rs); printHR(); echo "tableInfo"; echo $res->tableInfo(); /* printBR(); echo "Affected rows\n"; $sql = "DELETE FROM _test"; // use your own table:) $rs = $conn->query($sql); assertObject($rs); echo 'I have deleted ' . $conn->affectedRows() . ' rows'; printHR(); */ printHR(); printH2("Sequences"); $rs = $conn->nextId("alex_3"); assertObject($rs); echo $rs; printBR(); $rs = $conn->nextId("alex_3"); assertObject($rs); echo $rs; printHR(); printH2("Free the results"); // $rs->free(); no need after sequence stuff assertObject($conn); $conn->disconnect(); assertObject($conn); echo "done"; function printHR() { echo "
\n
\n
"; } // end func function printBR() { echo "
"; } // end func function assertObject(&$obj) { if (DB::isError($obj)) { die ($obj->toString()); } } // end func function printLoop(&$obj, &$counter) { assertObject($obj); echo "
" . $counter++ . "
"; printBR(); echo var_dump($obj); printBR(); } // end func () function printH2($caption="") { echo "
" . $caption . "
"; } // end func () ?>