php連接與操作PostgreSQL數(shù)據(jù)庫的方法
更新時間:2014年12月25日 08:58:19 投稿:shichen2014
這篇文章主要介紹了php連接與操作PostgreSQL數(shù)據(jù)庫的方法,以實例形式較為詳細(xì)的分析了php連接PostgreSQL數(shù)據(jù)庫以及進行讀取與增加、修改、刪除等技巧,具有一定的參考借鑒價值,需要的朋友可以參考下
本文實例講述了php連接與操作PostgreSQL數(shù)據(jù)庫的方法。分享給大家供大家參考。
具體實現(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);//輸出多少條記錄被插入
//}
//實例一[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>";
//實例二[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>";
//增加,刪除,修改實例
//$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è)計有所幫助。
您可能感興趣的文章:
相關(guān)文章
php實現(xiàn)事件監(jiān)聽與觸發(fā)的方法
這篇文章主要介紹了php實現(xiàn)事件監(jiān)聽與觸發(fā)的方法,可實現(xiàn)時間的綁定、觸發(fā)與注銷等功能,具有一定的參考借鑒價值,需要的朋友可以參考下2014-11-11file_get_contents獲取不到網(wǎng)頁內(nèi)容的解決方法
file_get_contents獲取不到網(wǎng)頁內(nèi)容的解決方法,需要的朋友可以參考一下2013-03-03php中g(shù)et_defined_constants函數(shù)用法實例分析
這篇文章主要介紹了php中g(shù)et_defined_constants函數(shù)用法,實例分析了get_defined_constants函數(shù)的功能、定義及使用技巧,需要的朋友可以參考下2015-05-05php include,include_once,require,require_once
其實PHP包含文件的這四個函數(shù),很多人還是沒完全明白的,雖然用的時候多,但是具體某些地方該怎么用,用那一個,我就獻丑一把.2008-09-09