PostgreSQL连接数据的方法和操作实例
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-11 22:39:28 浏览: 评论:0
- $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.");//开源代码phpfensi.com
- //if($reusult)
- //{
- //echo "rechords inserted sucessfully!";
- //}
- //
- pg_close($pg);
Tags: PostgreSQL连接数据 PostgreSQL实例
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)