用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > php教程

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

时间:2015-01-23  来源:西部数据  作者:西部数据
  1. $pg=@pg_connect("host=localhost user=postgres password=sa dbname=employes"
  2. or die("can't connect to database."); 
  3. $query="select * from employes order by serial_no"
  4. //$query="insert into employes values(10008,'susan','1985-09-04','80','50')"; 
  5. $result=@pg_query($pg,$queryor die("can't run query to table."); 
  6. //echo pg_num_rows($result); //输出多少条记录被查询 
  7. //if($result) 
  8. //{ 
  9. //echo "recrods inserted sucessfully!"; 
  10. //echo pg_affected_rows($result);//输出多少条记录被插入 
  11. //} 
  12. //实例一[pg_fetch_row] 
  13. echo "<table border=1>"
  14. echo "<tr>"
  15. echo "<td>serial_no</td>"
  16. echo"<td>name</td>"
  17. echo"<td>birthday</td>"
  18. echo"</tr>"
  19. for($i=0;$i<pg_num_rows($result);$i++) 
  20. $row=@pg_fetch_row($resultor die("can't fetch row from table."); 
  21. $serial_no$row[0]; 
  22. $name$row[1]; 
  23. $birthday$row[2]; 
  24. echo"<tr>"
  25. echo"<td>$serial_no</td>"
  26. echo"<td>$name</td>"
  27. echo"<td>$birthday</td>"
  28. echo"</tr>"
  29. echo"</table>"
  30. //实例二[pg_fetch_array] 
  31. //echo "<table border=1>"; 
  32. //echo "<tr>"; 
  33. //echo "<td>serial_no</td>"; 
  34. //echo"<td>name</td>"; 
  35. //echo"<td>birthday</td>"; 
  36. //echo"</tr>"; 
  37. // 
  38. //for($i=0;$i<pg_num_rows($result);$i++) 
  39. //{ 
  40. // 
  41. //$row=@pg_fetch_array($result) or die("can't fetch row from table."); 
  42. //$serial_no= $row['serial_no']; 
  43. //$name= $row['name']; 
  44. //$birthday= $row['birthday']; 
  45. //echo"<tr>"; 
  46. //echo"<td>$serial_no</td>"; 
  47. //echo"<td>$name</td>"; 
  48. //echo"<td>$birthday</td>"; 
  49. //echo"</tr>"; 
  50. // 
  51. //} 
  52. //echo"</table>"; 
  53. //增加,删除,修改实例 
  54. //$newrow=array("serial_no"=>"1006","name"=>"peter","birthday"=>"1990-07-03","salary"=>"90","bonus"=>"80"); 
  55. //$reusult=@pg_insert($pg,"employes",$newrow) or die("can't insert data to table.");//开源代码phpfensi.com 
  56. //if($reusult) 
  57. //{ 
  58. //echo "rechords inserted sucessfully!"; 
  59. //} 
  60. // 
  61. pg_close($pg);
来顶一下
返回首页
返回首页
推荐资讯
WiFi太不安全:7岁女孩11分钟内入侵公共网络 WiFi太不安全:7岁女孩11分钟内入侵近期刚刚发布研究说WiFi网络能获得人们手机里多少私人信息,
不服跑个分?人工智能也出现“刷分”乱象 不服跑个分?人工智能也出现“刷分2014年,人工智能领域突然爆发,成为了科研和科技创业的热门
相关文章
    无相关信息
栏目更新
栏目热门