Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A simple MySQL/MariaDB database wrapper in PHP.
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A simple MySQL/MariaDB database wrapper in PHP.

Copyright (C) 2011-2014 Jublo Solutions

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see


  • PHP 5.2.0 or higher

First steps

// load monty
require 'monty/loader.php';

// get the MySQL connector
$connector = Monty::getConnector();

// connect to a database
$connector->open('youruser', 'fancypass', 'holydatabase');

// not running the database on localhost? add a 4th parameter like this:
// $db->open('youruser', 'fancypass', 'holydatabase', '');

// want persistent connection? add a 5th parameter like this:
// $db->open('youruser', 'fancypass', 'holydatabase', '', MONTY_OPEN_PERSISTENT);

// now there's two operation modes:
// the EASY one first
$table = $connector->table('themaintable');

// want multiple tables?
// $table->add('anothertable');

// set a condition
$table->where('field', '=', 'value');

// there are some shortcuts, like this one:
// $table->eq('field', 'value');

// you might also want to use ands/ors
// $table->or($table->eq('field1', 'value1'),
//               $table->like('field2', 'value2'));
// equals:
// ... WHERE field1 = "value1" OR field2 LIKE "value2"

// peek at the generated sql code
echo $table->sql() . '<br />';

// loop through the results and display them
for($i = 0; $i < $table->rows(); $i++) {
    $row_array = $table->next();
    echo $row_array['field'] . ' = ' . $row_array['value'] . '<br />';

// you could also have got an object instead, like this:
// $row = $table->next(MONTY_NEXT_OBJECT);
// echo $row->field;

// for setting the object return type as default, put this statement
// at the top of your code:
// $table->setReturnType(MONTY_ALL_OBJECT);

// you can also run raw SQL like this (the nerd mode):
$connector->query('SELECT * FROM themaintable WHERE field = "value"');
echo $connector->rows();

// check if a certain table exists at the moment:
if ($connector->tableExists('the_table')) {
    // do something
Something went wrong with that request. Please try again.