php連接與操作PostgreSQL數(shù)據(jù)庫(kù)的方法
更新時(shí)間:2014年12月25日 08:58:19 投稿:shichen2014
這篇文章主要介紹了php連接與操作PostgreSQL數(shù)據(jù)庫(kù)的方法,以實(shí)例形式較為詳細(xì)的分析了php連接PostgreSQL數(shù)據(jù)庫(kù)以及進(jìn)行讀取與增加、修改、刪除等技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了php連接與操作PostgreSQL數(shù)據(jù)庫(kù)的方法。分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
$pg=@pg_connect("host=localhost user=postgres password=sa dbname=employes")
or die("can't connect to database.");
$query="select * from employes order by serial_no";
//$query="insert into employes values(10008,'susan','1985-09-04','80','50')";
$result=@pg_query($pg,$query) or die("can't run query to table.");
//echo pg_num_rows($result); //輸出多少條記錄被查詢
//if($result)
//{
//echo "recrods inserted sucessfully!";
//echo pg_affected_rows($result);//輸出多少條記錄被插入
//}
//實(shí)例一[pg_fetch_row]
echo "<table border=1>";
echo "<tr>";
echo "<td>serial_no</td>";
echo"<td>name</td>";
echo"<td>birthday</td>";
echo"</tr>";
for($i=0;$i<pg_num_rows($result);$i++)
{
$row=@pg_fetch_row($result) or die("can't fetch row from table.");
$serial_no= $row[0];
$name= $row[1];
$birthday= $row[2];
echo"<tr>";
echo"<td>$serial_no</td>";
echo"<td>$name</td>";
echo"<td>$birthday</td>";
echo"</tr>";
}
echo"</table>";
//實(shí)例二[pg_fetch_array]
//echo "<table border=1>";
//echo "<tr>";
//echo "<td>serial_no</td>";
//echo"<td>name</td>";
//echo"<td>birthday</td>";
//echo"</tr>";
//
//for($i=0;$i<pg_num_rows($result);$i++)
//{
//
//$row=@pg_fetch_array($result) or die("can't fetch row from table.");
//$serial_no= $row['serial_no'];
//$name= $row['name'];
//$birthday= $row['birthday'];
//echo"<tr>";
//echo"<td>$serial_no</td>";
//echo"<td>$name</td>";
//echo"<td>$birthday</td>";
//echo"</tr>";
//
//}
//echo"</table>";
//增加,刪除,修改實(shí)例
//$newrow=array("serial_no"=>"1006","name"=>"peter","birthday"=>"1990-07-03","salary"=>"90","bonus"=>"80");
//$reusult=@pg_insert($pg,"employes",$newrow) or die("can't insert data to table.");
//if($reusult)
//{
//echo "rechords inserted sucessfully!";
//}
//
pg_close($pg);
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- PostgreSQL管理工具phpPgAdmin入門指南
- PHP 讀取Postgresql中的數(shù)組
- PHP實(shí)現(xiàn)基于PDO擴(kuò)展連接PostgreSQL對(duì)象關(guān)系數(shù)據(jù)庫(kù)示例
- PHP操作Postgresql封裝類與應(yīng)用完整實(shí)例
- PHP實(shí)現(xiàn)從PostgreSQL數(shù)據(jù)庫(kù)檢索數(shù)據(jù)分頁(yè)顯示及根據(jù)條件查找數(shù)據(jù)示例
- PHP5中使用PDO連接數(shù)據(jù)庫(kù)的方法
- PHP PDO函數(shù)庫(kù)詳解
- PHP連接及操作PostgreSQL數(shù)據(jù)庫(kù)的方法詳解
相關(guān)文章
php和js如何通過json互相傳遞數(shù)據(jù)相關(guān)問題探討
json是js的一種數(shù)據(jù)格式,可以直接被js解析,php無法直接讀取json數(shù)據(jù),但是php提供了json_decode函數(shù)來對(duì)json數(shù)據(jù)進(jìn)行轉(zhuǎn)化,從而可以被php腳本訪問,今天,站長(zhǎng)就和大家一起來探討這個(gè)問題,感興趣的你可以參考下哦2013-02-02
PHP基于遞歸實(shí)現(xiàn)的約瑟夫環(huán)算法示例
這篇文章主要介紹了PHP基于遞歸實(shí)現(xiàn)的約瑟夫環(huán)算法,結(jié)合實(shí)例形式較為詳細(xì)的分析了約瑟夫環(huán)問題與php使用遞歸算法的解決方法,需要的朋友可以參考下2017-08-08
用php代碼限制國(guó)內(nèi)IP訪問我們網(wǎng)站
這篇文章主要介紹了用php代碼限制國(guó)內(nèi)IP訪問我們網(wǎng)站,需要的朋友可以參考下2015-09-09
對(duì)php 判斷http還是https,以及獲得當(dāng)前url的方法詳解
今天小編就為大家分享一篇對(duì)php 判斷http還是https,以及獲得當(dāng)前url的方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-01-01

