开发者

Generic PHP MySQL connection class

开发者 https://www.devze.com 2023-01-13 15:11 出处:网络
Are there any great, lightweight MySQL connection classes out there开发者_如何学编程 for PHP that anyone recommends?

Are there any great, lightweight MySQL connection classes out there开发者_如何学编程 for PHP that anyone recommends?

I have written my own, and I do think it is pretty good but this seems like the sort of thing that many programmers better than me must have perfected long ago.

I'm interested in finding something that I can slot in generically and use as I need it with as little hassle as possible.

Some generic functions to support querying, connecting to multiple MySQL databases within the one application would also be a plus.


Have you had a look at PDO? http://php.net/manual/en/book.pdo.php


PHP's PDO (PHP Data Objects) extension is my recommendation. I use it alongside a light-weight 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.


A class of my own invention: DB

It may be called very lightweight (less than 100 lines of code). It is a wrapper around PDO and it actually only adds a very handy way of escaping variables and a short syntax (DB::query() instead of DB::instance()->query().)

But this short syntax results in it being limited to once connection.


The simplest and lightweight db class is

http://code.google.com/p/edb-php-class/

<?php
$result = $db->q("select * from `users`limit 3");

foreach($result as $a){
        $a = (object) $a;
        echo $a->id.' '.$a->name.' '.$a->url.' '.$a->img.'</br>';
}


$result = $db->line("select * from `users` where id = '300' limit 1");
echo $result['name']; 
echo $result['surname']; 



$name = $db->one("select name from `ilike_pics` where id = '300' limit 1");
echo $name;
?>


this is a very neat and easy to use class: http://justinvincent.com/ezsql

wordpress database class is also derived from the above class


May try ADOdb and ADOdb Lite

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号