Useful PHP database class

前端 未结 11 1216
生来不讨喜
生来不讨喜 2021-02-06 06:21

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 ma

相关标签:
11条回答
  • 2021-02-06 07:03

    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");  
    
    0 讨论(0)
  • 2021-02-06 07:04

    I've used this once in a while, It's pretty good! (And has an awesome autoslash feature), it's easily customizable and pretty small, but it had everything I needed. You can probably relatively easy expand it to support caching or whatever you desire.

    Good luck finding whatever suits you best. :)

    0 讨论(0)
  • 2021-02-06 07:07

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

    0 讨论(0)
  • 2021-02-06 07:08

    If you don't have really specific needs, I would recommend you take a look at PDO, which is bundled with PHP >= 5.1.

    It's fully object-oriented, facilitates compatibility between DB engines ; and it's integration in PHP as a C extension makes it probably a bit faster than equivalents developped in PHP.

    You could also take a look at the mysqli extension, which provides both a function-oriented and an object-oriented interface.
    But I'd rather go to PDO, I think...


    And, now that you are spending (investing ;-) ) some time looking for new stuff, you could take a look at prepared statements : they are supported by both mysqli and PDO, and are nice for (amongst other things) security reasons (no need to worry about escaping your data to prevent SQL injections)


    If you had said you need a full ORM solution, I would have pointed you to Doctrine, which is really a great ORM framework ; but it's probably way too much for your needs...

    0 讨论(0)
  • 2021-02-06 07:10

    +1 for PHP's PDO (PHP Data Objects) extension. I use it alongside a really handy database class that extends PDO. You can find this open-source project on Google's Project Hosting at http://code.google.com/p/php-pdo-wrapper-class.

    0 讨论(0)
提交回复
热议问题