数据库

 首页 > 数据库 > postgresql > PostgreSQL事务功能与PHP编程

PostgreSQL事务功能与PHP编程

分享到:
【字体:
导读:
         摘要:!--CodehighlightingproducedbyActiproCodeHighlighter(freeware)http://www.CodeHighlighter.com/--classpgsql{private$linkid;//PostgreSQL连接标识符private$host;//PostgreS...

PostgreSQL事务功能与PHP编程
!--

  Code highlighting produced byActiproCodeHighlighter(freeware)

  http://www.CodeHighlighter.com/

  -->

  class pgsql {

  private$linkid;//PostgreSQL连接标识符

  private$host;//PostgreSQL服务器主机

  private $user; //PostgreSQL用户

  private $passwd; //PostgreSQL密码

  private $db; //Postgresql数据库

  private$result;//查询的结果

  private$querycount;//已执行的查询总数

  /*类构造函数,用来初始化$host、$user、$passwd和$db字段。*/

  function __construct($host, $db, $user, $passwd){

  $this->host = $host;

  $this->user = $user;

  $this->passwd = $passwd;

  $this->db = $db;

  }

  /*连接Postgresql数据库 */

  function connect(){

  try{

  $this->linkid=@pg_connect(host=$this->hostdbname=$this->db

  user=$this->userpassword=$this->passwd);

  if (! $this->linkid)

  throw new Exception(Could not connect toPostgreSQLserver.);

  }

  catch (Exception $e) {

  die($e->getMessage());

  }

  }

  /*执行数据库查询。*/

  function query($query){

  try{

  $this->result =@pg_query($this->linkid,$query);

  throw new Exception(The database queryfailed.);

  }

  catch (Exception $e){

  echo $e->getMessage();

  }

  $this->querycount++;

  return $this->result;

  }

  /*确定受查询所影响的行的总计。*/

  function affectedRows(){

  $count = @pg_affected_rows($this->linkid);

  return $count;

  }

  /*确定查询返回的行的总计。*/

  function numRows(){

  $count = @pg_num_rows($this->result);

  return $count;

  }

  /*将查询的结果行作为一个对象返回。*/

  function fetchObject(){

  $row = @pg_fetch_object($this->result);

  return $row;

  }

  /*将查询的结果行作为一个索引数组返回。*/

  function fetchRow(){

  $row = @pg_fetch_row($this->result);

  return $row;

  }

  /*将查询的结果行作为一个关联数组返回。*/

  function fetchArray(){

  $row = @pg_fetch_array($this->result);

  return $row;

  }

PostgreSQL事务功能与PHP编程
分享到:
PostgreSQL与MySQL之间的选择
PostgreSQL与MySQL之间的选择   为企业选择一个适合的数据库,需要做一个相当长远的打算,因为如果日后改变选择,将付出非常艰难又昂贵的代价。所以必须第一次就做出正确的选择。MySQL和PostgreSQL是两个最受欢迎的开源数据库,它们往往是数据库管理员准备进行新的部署时最终的两个候选。本文通过对这两个开源数据库的概...
使用Node.js 操作 postgresql 数据库
使用Node.js 操作 postgresql 数据库 上一篇node.js访问postgresql数据库,主要是在同一个文件里面实现对数据库的操作。 这篇node.js操作postgresql数据库,采用的是两个文件的方式实现,一个文件相当于客户端,实现连接数据库,调用相应的函数,而另一个文件是具体实现函数的。 在你安装了node.js,postgresql数据...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……