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 "
| serial_no | name | birthday |
| $serial_no | $name | $birthday |
//实例二[pg_fetch_array]
//echo "
| serial_no | name | birthday |
| $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);
期望上述关于PHP程序设计的内容能对读者在实际开发中有所帮助。