这篇文章主要介绍了php连接与操作PostgreSQL数据库的方法,以实例形式较为详细的分析了php连接PostgreSQL数据库以及进行读取与增加、修改、删除等技巧,具有一定的
本文实例讲述了php连接与操作PostgreSQL数据库的方法。分享给大家供大家参考。
具体实现方法如下:
复制代码 代码如下:
$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 "
";
echo "";
echo "serial_no | ";
echo"name | ";
echo"birthday | ";
echo"
";
for($i=0;$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"";
echo"$serial_no | ";
echo"$name | ";
echo"$birthday | ";
echo"
";
}
echo"
";
//实例二[pg_fetch_array]
//echo "
";
//echo "";
//echo "serial_no | ";
//echo"name | ";
//echo"birthday | ";
//echo"
";
//
//for($i=0;$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"";
//echo"$serial_no | ";
//echo"$name | ";
//echo"$birthday | ";
//echo"
";
//
//}
//echo"
";
//增加,删除,修改实例
//$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程序设计有所帮助。
,
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn