有用的PHP数据库类[英] Useful PHP database class

本文是小编为大家收集整理的关于有用的PHP数据库类的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在一个小型PHP网站上工作.我需要一个易于配置和使用的MySQL数据库访问类.

不需要是一个完整的框架,我只需要最大.几个课程.

推荐答案

adodb 很容易使用,值得考虑.一些说明性样本:

  //connect
  $dsn = 'mysql://user:pwd@localhost/mydb'; 
  $db = ADONewConnection($dsn);  

  //get a single value     
  $value=$db->GetOne("select foo from bar where x=?", array($x));

  //get a row
  $row=$db->GetRow("select * from bar where x=?", array($x));

  //easy insert example
  $record=array("id"=>1, "foo"=>"bar");
  $db->AutoExecute("table", $record, "INSERT");  

其他推荐答案

PDO对我来说很好,即使不是像Pear :: MDB2.

PDO是PHP5的编译扩展,因此性能也很小.

其他推荐答案

如果您对MySQL的特定感到满意,则 mysqli 是默认的选择.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

本文地址:https://www.itbaoku.cn/post/597745.html

问题描述

I am working on a small PHP website. I need a MySql database access class that is easy to configure and work with.

Does not need to be a full framework, I only need a max. few classes.

推荐答案

ADODb is pretty easy to work with and worth considering. Some illustrative samples:

  //connect
  $dsn = 'mysql://user:pwd@localhost/mydb'; 
  $db = ADONewConnection($dsn);  

  //get a single value     
  $value=$db->GetOne("select foo from bar where x=?", array($x));

  //get a row
  $row=$db->GetRow("select * from bar where x=?", array($x));

  //easy insert example
  $record=array("id"=>1, "foo"=>"bar");
  $db->AutoExecute("table", $record, "INSERT");  

其他推荐答案

PDO works great for me, even tho it's not a fully blown library like PEAR::MDB2.

PDO is a compiled extension of PHP5, so there's a small performance benefit as well.

其他推荐答案

If you're happy with it being MySql specific, MySqli is the default choice.