這篇文章主要介紹了PHP ADODB產生HTML表格函數rs2html功能,結合執行個體形式分析了php使用ADODB類使用函數rs2html輸出結果集產生HTML表格相關操作技巧,並附錯誤處理函數errorMsg用法,需要的朋友可以參考下
本文執行個體講述了PHP ADODB產生HTML表格函數rs2html功能。分享給大家供大家參考,具體如下:
一、代碼
adodb.inc.php可從官方網站http://adodb.sourceforge.net/ 下載。
conn.php:
<?php include_once ('../adodb5/adodb.inc.php'); $conn = ADONewConnection('mysql'); $conn -> PConnect('localhost','root','root','db_database14'); $conn -> execute('set names gb2312'); $ADODB_FETCH_MODE = ADODB_FETCH_BOTH;?>
rs2html.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>應用rs2html()函數直接輸出返回的結果集</title><style type="text/css"><!--TH {background-color:#FFFFFF; font-size: 12px; color: #FF0000;}td {background-color:#FFFFFF; font-size: 12px; color: #FF0000;}--></style></head><body><?php include_once 'conn/conn.php'; //載入資料庫連結檔案 include_once '../adodb5/tohtml.inc.php'; //載入tohtml.inc.php檔案 $rst = $conn -> execute('select * from tb_object'); //返回查詢結果集 rs2html($rst,' width="350" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FF0000"',array('序號','類別','添加時間')); //輸出結果集?></body></html>
二、運行結果
附:ADODB錯誤處理函數
<?php include_once 'conn/conn.php'; //載入資料庫連結檔案 $conn -> debug = true; //開啟調試 $sql = 'select * form tb_object'; //sql查詢語句 $rst = $conn -> execute($sql) or die($conn -> errorMsg()); //調用查詢語句?>
運行結果: