php连接与操作PostgreSQL数据库的方法
2015-01-24信息快讯网
这篇文章主要介绍了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 "<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程序设计有所帮助。
php实现redis数据库指定库号迁移的方法
php计划任务之ignore_user_abort函数实现方法
php的ddos攻击解决方法
php中$_POST与php://input的区别实例分析
PHP中使用xmlreader读取xml数据示例
VPS中使用LNMP安装WordPress教程
PHP中require和include路径问题详解
php使用pdo连接mssql server数据库实例
完整删除ecshop中获取店铺信息的API
PHP_SELF,SCRIPT_NAME,REQUEST_URI区别
php将access数据库转换到mysql数据库的方法
php实现refresh刷新页面批量导入数据的方法
php进行支付宝开发中return_url和notify_url的区别分析
CentOS6.5 编译安装lnmp环境
在SAE上搭建最新wordpress的方法
php中http与https跨域共享session的解决方法
php将textarea数据提交到mysql出现很多空格的解决方法
smarty中post用法实例
使用PHP Socket 编程模拟Http post和get请求
ThinkPHP中I(),U(),$this->post()等函数用法
PHP PDOStatement对象bindpram()、bindvalue()和bindcolumn之间的区别
PDO预处理语句PDOStatement对象使用总结
PHP图片处理之使用imagecopyresampled函数实现图片缩放例子
PHP图片处理之使用imagecopyresampled函数裁剪图片例子
php中current、next与reset函数用法实例