Archive for the ‘PHP’ Category

MySqlToMongoDB importer

21 August 2014 1 comment

Hello everybody, finally after many requests….

I create this class that import MySQL database into MongoDB.
It can connect to a given MySQL server to retrieve the records of the tables.
The class can recreate the table records and indexes in a given MongoDB.

In this version I limit the import to insert new records and don’t update
existing ones.If you want to update existing records just change the insert() method to save()
and mongodb library will update the object reference with new values.

You can download following this link:
Thanks to everybody to support me.
I’m avaiable for all your questions and suggests.

I appreciate if you fill the following pool:

Principe Orazio

Categories: Classes, MongoDB Tags: , , ,

MySqlHotBackup Tool

This class can backup a MySQL database copying records of updated tables to another database.

It can access the MySQL database to be backed up and recreates its tables in a backup database on the first run.

Later in can update the backup by just just updating the records of the tables that were changed in the origin database.

The class can skip some tables to be backed up. The number of records to be committed in the backup database can be limited.

Thanks to everybody who will use it and mostly rate it

Categories: MySQL, PHP


8 September 2012 Leave a comment

Hello word! Hi unify a lot of functions used every day by me and others developers
in a static class ready to use into your projects.

Why a static class?
Simply ’cause with it if you already have a function with the same name your script
will not crash ūüôā

Download it here

You can find complete documentation here:

Please post your comments and request on the main site

and not here.

Thanks to all contributors

DBPersister version 1.0 stable

dbpersister logo

DBPersister (Open Souce – LGPL licence)

I released the first stable version of this new library written for php that will easy you life with your classes and most mysql operations.

DBPersister will let you simply call CRUD methods like insert, update, delete, replace or simply “save” to persist data into database.

Moreover give you a lot of others possibility with all posted data by forms
or other infinite ways.

Download and try it

Follow the project on facebook at:

Categories: Classes, MySQL

Verify EAN 13 with PHP

23 March 2012 4 comments

Here the function to verify a correct EAN13 structure.

function validate_EAN13Barcode($barcode)
    // check to see if barcode is 13 digits long
    if (!preg_match("/^[0-9]{13}$/", $barcode)) {
        return false;

    $digits = $barcode;

    // 1. Add the values of the digits in the 
    // even-numbered positions: 2, 4, 6, etc.
    $even_sum = $digits[1] + $digits[3] + $digits[5] +
                $digits[7] + $digits[9] + $digits[11];

    // 2. Multiply this result by 3.
    $even_sum_three = $even_sum * 3;

    // 3. Add the values of the digits in the 
    // odd-numbered positions: 1, 3, 5, etc.
    $odd_sum = $digits[0] + $digits[2] + $digits[4] +
               $digits[6] + $digits[8] + $digits[10];

    // 4. Sum the results of steps 2 and 3.
    $total_sum = $even_sum_three + $odd_sum;

    // 5. The check character is the smallest number which,
    // when added to the result in step 4, produces a multiple of 10.
    $next_ten = (ceil($total_sum / 10)) * 10;
    $check_digit = $next_ten - $total_sum;

    // if the check digit and the last digit of the 
    // barcode are OK return true;
    if ($check_digit == $digits[12]) {
        return true;

    return false;
Categories: Functions, PHP

Verify if a table is locked by MySql

Many times you need to understand if a table still locked by mysql.
In this case you can use the following function to understand if it is or not.

* This function will check on the db name pass by the first param
* if one, or more tables, are locked by others processes
* Return true if just one of tables is locked
* @param string $db_name
* @param array $array_tables_names
* @return boolean
function tablesLocked($db_name, $array_tables_names)

//Take the instance of codeigniter
$ci = get_instance();

//Load the default configuration 
//(if your configuration name is different just change it)

//Check for locked tables
$sql = "SHOW OPEN TABLES FROM `".$db_name."`
WHERE In_use > 0
`Table` IN (";

$tables = count($array_tables_names);
for($i = 0; $i < $tables; $i++):
$sql .= "'".$array_tables_names[$i]."'";
if($i < ($tables-1)) $sql .= ",";

$sql .= ")";
$rs = $ci->db->query($sql);
return $rs->num_rows() > 0;

Categories: CodeIgniter, Functions, PHP

watermark image with php and ImageMagick

Here a simple function that use ImageMagick command to apply a watermark image as background of another one.

* Direct command from imagemagick
* composite -dissolve 15 -tile watermark.png source.jpg destination.jpg
* @param string $watermarkfile
* @param string $sourcefile
* @param string $destfile
* @param int $dissolve
* @return boolean
function watermarkImage($watermarkfile, $sourcefile, $destfile, $dissolve = 5)
$cmd = "/usr/bin/composite -dissolve $dissolve -tile $watermarkfile $sourcefile $destfile";

exec($cmd, $output, $return);
return $return === 0;

Categories: Bash scripting, Functions, PHP
%d bloggers like this: