国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP連接數據庫的方法(2)

2024-05-04 23:02:07
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。

 

if($field_value==""){

echo "<td> </td>";

}

else{

echo "<td>$field_value</td>";

}

}

echo "</tr>";

}

echo "</table>";//
表格輸出結束

mysql_free_result($rst) or die("
無法釋放result資源!");//釋放result資源

}

else{

echo "
目前該表中沒有任何數據!";

}

mysql_close($server) or die("
無法與服務器斷開連接!");//斷開連接并釋放資源

?>

開放數據庫連接(odbc)已成為一種與數據庫進行通信的工業標準。php也提供了標準的接口,使得php能調用accesssql server等數據庫。其相關函數是:

1integer odbc_connect(string dsn, string user, string password)

連接到一個odbc數據庫源名字上。

2integer odbc_exec(integer connection, string query) odbc_do(integer connection, string query)

在一個連接上執行查詢。

3boolean odbc_fetch_row(integer result, integer row)

從一個結果集中獲取一行數據。row參數是可選的,若為空缺,則返回下一個有效行。在結果集中不再剩余行時返回false

4boolean odbc_close(integer connection)

關閉一個數據庫的連接。若在該連接上有打開的事務,則返回一個錯誤,而且連接不會被關閉。

最后,還是看個分頁的例子:

<?

//
設定每頁顯示條數

$show_num = 10;

$spages = $pages;//
避免$pages后期被改變

//
定義連接

$dsn = "localhost";

$user = "sa";

$password = "";

//
計算總記錄數

$rs_num = "select count(*) as id from bbs where zu='0' and lei='".$lei."'";

$conn_id = odbc_connect($dsn,$user,$password);

$rnum = odbc_exec($conn_id,$rs_num);

while(odbc_fetch_row($rnum)){

$total_rs = odbc_result($rnum,"id");//
將總記錄數放入$total_rs變量

}

//
計算與頁有關的條數

$nnn = $total_rs / $show_num;//
計算總頁數

$hnnn = intval($nnn);//
將總頁數取整

$cnnnn = $nnn - $hnnn;

//
計算所需總頁數

switch ($cnnn){

case "0":

$hnnn++;

$nnn = $hnnn;//
總頁數

break;

default :

$nnn = $hnnn;//
總頁數

break;

};

if ($nnn == 0)$nnn++;

//
計算頁面改變所需的條件

$fore = $pages;

$next = $pages;

$fore -= 1;

$next += 1;

if ($fore > 0) {

echo "<a>
首頁</a>";

echo "<a>
前頁</a>";

};

if ($pages < $nnn) {

echo "<a>
后頁</a>";

echo "<a>
尾頁</a>";

};

echo "
".$nnn."";

$query_string = "select * from table where condition order by you wanted order";

$cur = odbc_exec($conn_id,$query_string);

//
取到循環的頂部

$cnum = ($pages-1) * $show_num;//
計算當前的記錄游標的位置

//
空循環到顯示記錄游標處

if ($cnum != 0){

for ($i=0;$i<=$cnum;odbc_fetch_row($cur)){$i++;};

};

$i=1;

//
顯示記錄

while(odbc_fetch_row($cur)){

echo ;

if ($i == $show_num){//
在不滿頁數時跳出程序

break;

};

$i++;

};

//
關閉連接

odbc_close($conn_id);

?>

oracle
(甲骨文)是世界上最為流行的關系數據庫。它是大公司推崇的工業化的強有力的引擎。我們先看看其相關的函數:

1integer ora_logon(string user , string password)

開始對一個oracle數據庫服務器的連接。

2integer ora_open(integer connection)

打開給出的連接的游標。

3integer ora_do(integer connection, string query)

在給出的連接上執行查詢。php生成一個指示器,解析查詢,并執行之。

4integer ora_parse(integer cursor, string query)

解析一個查詢并準備好執行。

5boolean ora_exec(integer cursor)

執行一個先前由ora_parse函數解析過的查詢。

6boolean ora_fetch(integer cursor)

此函數會使得一個執行過的查詢中的行被取到指示器中。這使得您可以調用ora_getcolumn函數。

7string ora_getcolumn(integer cursor, integer column)

返回當前的值。列由零開始的數字索引。

8boolean ora_logoff(integer connection)

斷開對數據庫服務器的鏈接。

以下是向oracle數據庫插入數據的示例程序:

<html>

<head><title>
oracle數據庫中插入數據</title></head>

<body>

<form action="<?echo $php_self;?>" method="post">

<table border="1" cellspacing="0" cellpadding="0">

<tr>

<th>id</th>

<th>name</th>

<th>description</th>

</tr>

<tr>

<td><input type="text" name="name" maxlength="50" size="10"></td>

<td><input type="text" name="email" maxlength="255" size="30"></td>

<td><input type="text" name="description" maxlength="255" size="50"></td>

</tr>

<tr align="center">

<td colspan="3"><input type="submit" value="
提交">&nbsp;&nbsp;<input type="reset" value="重寫"></td>

</tr>

</table>

</form>

<?

//
先設置兩個環境變量oracle_homeoracle_sid

putenv("oracle_home=/oracle/app/oracle/product/8.0.4");

putenv("oracle_sid=ora8");

//
設置網頁顯示中文

putenv("nls_lang=simplified_chinese.zhs16cgb231280");

if($connection=ora_logon("scott","tiger")) {

//
庫表testid,name,description三項

$sql = 'insert into test(id,name,description) values ';

$sql .= '('' . $id . '','' . $name . '',''. $description . '')';

if($cursor=ora_do($connect,$sql)) {

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵石县| 长垣县| 射阳县| 贺州市| 遂昌县| 疏附县| 肃南| 亚东县| 平泉县| 延吉市| 讷河市| 鄂温| 丹东市| 张家界市| 南郑县| 凤翔县| 特克斯县| 青海省| 长垣县| 贺兰县| 乐昌市| 石嘴山市| 邹平县| 南陵县| 定州市| 香港| 舞阳县| 长兴县| 临夏县| 偏关县| 前郭尔| 武宁县| 拜泉县| 集安市| 延津县| 嘉善县| 鸡泽县| 扶风县| 夏津县| 太保市| 石泉县|