Last Updated: February 25, 2016
·
2.616K
· penguinpaul

Great PHP DB Classes

If you need a nice OOP class for connecting to a database; check out what MyBB has. It supports MySQL, MySQL Improved, SQLite, PDO, and PostgreSQL, as well as master/slave replication. They can be used very easily outside of MyBB; plus, they're open source, so you can include them in your projects for free.

They have very easy methods to interact with the database; here's a sample:

$username = $db->escape_string($_GET['username']);
$query = $db->simple_select("users","*","username='{$username}'");

$user = $db->fetch_array($query);

if($user['canChangePassword'] == '1')
{
    $password = $db->escape_string($_GET['password']);
    $user['password'] = md5($password);
    $db->update_query($user);
}

To check out these classes more, download MyBB here: http://www.mybb.com/download/latest

The DB classes are located in the ./inc/ folder, under the names db_[dbtype].php.