zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

php连接与操作PostgreSQL数据库的方法

2023-06-13 09:15:37 时间

本文实例讲述了php连接与操作PostgreSQL数据库的方法。分享给大家供大家参考。

具体实现方法如下:

复制代码代码如下:


$pg=@pg_connect("host=localhostuser=postgrespassword=sadbname=employes")
ordie("can"tconnecttodatabase.");
$query="select*fromemployesorderbyserial_no";
//$query="insertintoemployesvalues(10008,"susan","1985-09-04","80","50")";
$result=@pg_query($pg,$query)ordie("can"trunquerytotable.");
//echopg_num_rows($result);//输出多少条记录被查询
//if($result)
//{
//echo"recrodsinsertedsucessfully!";
//echopg_affected_rows($result);//输出多少条记录被插入
//}
//实例一[pg_fetch_row]
echo"<tableborder=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)ordie("can"tfetchrowfromtable.");
$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"<tableborder=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)ordie("can"tfetchrowfromtable.");
//$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)ordie("can"tinsertdatatotable.");
//if($reusult)
//{
//echo"rechordsinsertedsucessfully!";
//}
//
pg_close($pg);

希望本文所述对大家的PHP程序设计有所帮助。