php連接與操作PostgreSQL數(shù)據(jù)庫的方法
本文實(shí)例講述了php連接與操作PostgreSQL數(shù)據(jù)庫的方法。分享給大家供大家參考。
具體實(shí)現(xiàn)方法如下:
$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);
希望本文所述對大家的PHP程序設(shè)計(jì)有所幫助。
- PostgreSQL管理工具phpPgAdmin入門指南
- PHP 讀取Postgresql中的數(shù)組
- PHP實(shí)現(xiàn)基于PDO擴(kuò)展連接PostgreSQL對象關(guān)系數(shù)據(jù)庫示例
- PHP操作Postgresql封裝類與應(yīng)用完整實(shí)例
- PHP實(shí)現(xiàn)從PostgreSQL數(shù)據(jù)庫檢索數(shù)據(jù)分頁顯示及根據(jù)條件查找數(shù)據(jù)示例
- PHP5中使用PDO連接數(shù)據(jù)庫的方法
- PHP PDO函數(shù)庫詳解
- PHP連接及操作PostgreSQL數(shù)據(jù)庫的方法詳解
相關(guān)文章
php flush無效,IIS7下php實(shí)時(shí)輸出的方法
這篇文章主要介紹了php flush無效,IIS7下php實(shí)時(shí)輸出的方法,需要的朋友可以參考下2016-08-08php實(shí)現(xiàn)事件監(jiān)聽與觸發(fā)的方法
這篇文章主要介紹了php實(shí)現(xiàn)事件監(jiān)聽與觸發(fā)的方法,可實(shí)現(xiàn)時(shí)間的綁定、觸發(fā)與注銷等功能,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11file_get_contents獲取不到網(wǎng)頁內(nèi)容的解決方法
file_get_contents獲取不到網(wǎng)頁內(nèi)容的解決方法,需要的朋友可以參考一下2013-03-03PHP隨機(jī)數(shù)生成代碼與使用實(shí)例分析
在PHP程序設(shè)計(jì)中,隨機(jī)數(shù)的生成尤為重要。我們需要用隨機(jī)數(shù)在我們的頁面中展示隨機(jī)記錄(比如圖片、用戶記錄、文章ID等)。2011-04-04php中g(shù)et_defined_constants函數(shù)用法實(shí)例分析
這篇文章主要介紹了php中g(shù)et_defined_constants函數(shù)用法,實(shí)例分析了get_defined_constants函數(shù)的功能、定義及使用技巧,需要的朋友可以參考下2015-05-05php include,include_once,require,require_once
其實(shí)PHP包含文件的這四個(gè)函數(shù),很多人還是沒完全明白的,雖然用的時(shí)候多,但是具體某些地方該怎么用,用那一個(gè),我就獻(xiàn)丑一把.2008-09-09