>  기사  >  백엔드 개발  >  二款PostgreSQL连接数据的方法和操作实例_PHP教程

二款PostgreSQL连接数据的方法和操作实例_PHP教程

WBOY
WBOY원래의
2016-07-13 17:04:37905검색

二款PostgreSQL连接数据的方法和操作实例

二款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 "";
echo"";
echo"";
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"";
echo"";
echo"";
echo"";

}
echo"

serial_nonamebirthday
$serial_no$name$birthday
";

//实例二[pg_fetch_array]
//echo "

";
//echo "";
//echo "";
//echo"";
//echo"";
//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"";
//echo"";
//echo"";
//echo"";
//
//}
//echo"
serial_nonamebirthday
$serial_no$name$birthday
";

//增加,删除,修改实例
//$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);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630835.htmlTechArticle二款PostgreSQL连接数据的方法和操作实例 二款postgresql连接数据的方法和操作实例. $pg=@pg_connect(host=localhost user=postgres password=sa dbname=employes)...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.