|
1樓 118.117.20.*
2015-6-14 14:18
<?php $dsn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=E:\\Databases\data.mdb"; $conn = odbc_connect($dsn, "", "") or die ("Failed connecting to the Access Database"); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Microsoft Access 2003</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css"> <!-- body,td,th { font-size: 13px; font-family: Arial, Helvetica, sans-serif; } --> </style></head> <body> <?php $sql = "SELECT * FROM Products ORDER BY ProductID ASC"; $rs = odbc_exec($conn, $sql); ?> <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#66CC00"> <tr> <td width="60" height="21" align="center" bgcolor="#E7FFD7">产品编号</td> <td height="21" align="center" bgcolor="#E7FFD7">产品名称</td> <td width="200" align="center" bgcolor="#E7FFD7">产品描述</td> <td width="70" height="21" align="center" bgcolor="#E7FFD7">产品价格</td> </tr> <?php while ($row = odbc_fetch_array($rs)) { ?> <tr> <td width="60" height="28" align="center" bgcolor="#E7FFD7"><?=$row["ProductID"]?></td> <td height="28" align="center" bgcolor="#FFFFFF"><?=$row["ProductName"]?></td> <td width="200" align="center" bgcolor="#FFFFFF"><?=$row["ProductDescription"]?></td> <td width="70" height="28" align="center" bgcolor="#FFFFFF">$<?=$row["ProductPrice"]?></td> </tr> <?php } ?> </table> </body> </html> <?php odbc_close($conn); ?>
|
|
2樓 118.117.20.*
2015-6-14 14:19
输出内容:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Microsoft Access 2003</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css"> <!-- body,td,th { font-size: 13px; font-family: Arial, Helvetica, sans-serif; } --> </style></head> <body> <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#66CC00"> <tr> <td width="60" height="21" align="center" bgcolor="#E7FFD7">产品编号</td> <td height="21" align="center" bgcolor="#E7FFD7">产品名称</td> <td width="200" align="center" bgcolor="#E7FFD7">产品描述</td> <td width="70" height="21" align="center" bgcolor="#E7FFD7">产品价格</td> </tr> <tr> <td width="60" height="28" align="center" bgcolor="#E7FFD7">1</td> <td height="28" align="center" bgcolor="#FFFFFF">Android</td> <td width="200" align="center" bgcolor="#FFFFFF">An android book</td> <td width="70" height="28" align="center" bgcolor="#FFFFFF">$5.85</td> </tr> <tr> <td width="60" height="28" align="center" bgcolor="#E7FFD7">2</td> <td height="28" align="center" bgcolor="#FFFFFF">Spanish</td> <td width="200" align="center" bgcolor="#FFFFFF">For Spanish learners</td> <td width="70" height="28" align="center" bgcolor="#FFFFFF">$10.73</td> </tr> <tr> <td width="60" height="28" align="center" bgcolor="#E7FFD7">3</td> <td height="28" align="center" bgcolor="#FFFFFF">English</td> <td width="200" align="center" bgcolor="#FFFFFF">For English beginners</td> <td width="70" height="28" align="center" bgcolor="#FFFFFF">$40.5</td> </tr> <tr> <td width="60" height="28" align="center" bgcolor="#E7FFD7">4</td> <td height="28" align="center" bgcolor="#FFFFFF">PHP</td> <td width="200" align="center" bgcolor="#FFFFFF">A PHP Tutorial</td> <td width="70" height="28" align="center" bgcolor="#FFFFFF">$15.36</td> </tr> </table> </body> </html>
|
|
3樓 118.117.20.*
2015-6-14 14:21
这是一个PHP连接Access 2003数据库的示例。
|
|
4樓 118.117.20.*
2015-6-14 16:14
$conn = odbc_connect($dsn, "", "", SQL_CUR_USE_ODBC) or die ("Failed connecting to the Access Database");
用SQL_CUR_USE_ODBC可以避免一些错误。
|
|
5樓 118.117.20.*
2015-6-14 16:18
...
<p><?=odbc_num_rows($rs)?></p> </body> </html> <?php odbc_free_result($rs); odbc_close($conn); ?>
|
|
6樓 118.117.20.*
2015-6-14 16:19
mysql_free_result() 仅需要在考虑到返回很大的结果集时会占用多少内存时调用。在脚本结束后所有关联的内存都会被自动释放。
|