PHP串連ODBC的代碼

來源:互聯網
上載者:User

也不知道自已的IT路能走多長,以後也別技較一時的得失了,憑自己的興趣,能學多少就學多少了....

這是個用PHP串連ODBC的例子(抄來的),ODBC還要設定一下,注意要選報系統DSN,同事說用ODBC效能不太好!管它呢....

<?
/*本例是用PHP4通過ODBC訪問資料庫操作的示範*/
?>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style type="text/css">
<!--
input { font-size:9pt;}
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: none; font-size:9pt}
A:hover
body,table {font-size: 9pt}
tr,td
-->
</style>
<title>註冊會員列表 - 通過ODBC訪問資料庫示範</title>
</HEAD>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<br><br><center><font color=green size=3><b>注 冊 會 員 列 表</b></font></center>
<br>
<table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width="5%" align="center" valign="bottom" height="19">ID</td>
<td width="10%" align="center" valign="bottom">姓名</td>
<td width="5%" align="center" valign="bottom">性別</td>
<td width="5%" align="center" valign="bottom">年齡</td>
<td width="20%" align="center" valign="bottom">聯絡電話</td>
<td width="20%" align="center" valign="bottom">電子郵件</td>
<td width="20%" align="center" valign="bottom">家庭住址</td>
</tr>
<?
//串連到ODBC資料庫
$myconn=odbc_connect("phptest","sa","etc");
$strSql="select * from reguser";
/*執行查詢*/
$result=odbc_do($myconn,$strSql);
//Boolean odbc_fetch_row(integer result,integer row)
while(odbc_fetch_row($result))//通過迴圈讀取資料內容
{
?>
<tr>
<td align="center" height="19"><?echo odbc_result($result,1)?></td>
<td align="center"><?echo odbc_result($result,2)?></td>
<td align="center"><?echo odbc_result($result,3)?></td>
<td align="center"><?echo odbc_result($result,4)?></td>
<td align="center"><?echo odbc_result($result,5)?></td>
<td align="center"><?echo odbc_result($result,6)?></td>
<td align="center"><?echo odbc_result($result,7)?></td>
</tr>
<?
}
//關閉對資料庫的串連
odbc_close($myconn);
?>
</table>
</BODY>
</HTML>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.