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.

http://www.phpclasses.org/package/8424-PHP-Backup-a-MySQL-database-copying-tables-to-another.html

Thanks to everybody who will use it and mostly rate it

Categories: MySQL, PHP

Javascript get a nice uri from string


This function will transform a string into a nice uri.

You can use this to get a good level seo uri for all your links


function getNiceURI(_dirtyUri)
{
_dirtyUri = _dirtyUri.toLowerCase();
if(_dirtyUri === "") return _dirtyUri;

var encodedURI = encodeURIComponent(_dirtyUri);
var niceURI = encodedURI.replace(/[%20]/g,”_”);
niceURI = niceURI.replace(/[^a-zA-Z0-9-_]/g, ‘_’);

//Elimino eventuali underscore dal primo carattere
while(niceURI.indexOf(“_”) === 0) {
niceURI = _dirtyUri.substring(1, niceURI.length);
}

//Deleting underscores from beginning and end string
while(niceURI.lastIndexOf(“_”) === niceURI.length – 1) {
niceURI = niceURI.substring(0, niceURI.length – 1);
}

//Take off repeated underscores
while(niceURI.indexOf(“__”) !== -1) {
niceURI = niceURI.replace(“__”, “_”);
}

return niceURI;
}

PhpUtils

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:

http://www.dbpersister.com/phputils-documentation/class-PhpUtils.html

Please post your comments and request on the main site

www.dbpersister.com

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
http://www.dbpersister.com

Follow the project on facebook at:
https://www.facebook.com/dbpersister

Categories: Classes, MySQL

Simple date convertion with javascript


Following there are few functions in javascript that allow you to forget problems and dismiss boring codes to convert
a date with mysql format coming from some ajax calls using javascript:

PS: to use them you must use also the empty() function derived directly from php:

/** 
* Return the day value from a mysql date/datetime 
*/
function getDay(_mySqlDate) {

    if (empty(_mySqlDate)) return "";

    var _els = _mySqlDate.split("-");
    return _els[2].substring(0, 2);
}

/** 
* Return the month value from a mysql date/datetime 
*/
function getMonth(_mySqlDate) {
    if (empty(_mySqlDate)) return "";

    var _els = _mySqlDate.split("-");
    return _els[1].substring(0, 2);
}

/** 
* Return the year value from a mysql date/datetime 
*/
function getYear(_mySqlDate) {
    if (empty(_mySqlDate)) return "";

    var _els = _mySqlDate.split("-");
    return _els[0].substring(0, 4);
}

/** 
* Return the hours value from a mysql date/datetime 
*/
function getHours(_mySqlDate) {
    if (empty(_mySqlDate)) return "";

    if (_mySqlDate.indexOf(":") >= 0) {
        var _els = _mySqlDate.(" ");

        if (empty(_els[1])) {
            _els[1] = _els[0];
        }

        var _arrTimes = _els[1].split(":");
        return _arrTimes[0];
    } else {
        return "";
    }
}

/** 
* Return the minutes value from a mysql date/datetime 
*/
function getMinutes(_mySqlDate) {
    if (empty(_mySqlDate)) return "";

    if (_mySqlDate.indexOf(":") >= 0) {
        var _els = _mySqlDate.(" ");

        if (empty(_els[1])) {
            _els[1] = _els[0];
        }

        var _arrTimes = _els[1].split(":");
        return _arrTimes[1];
    } else {
        return "";
    }
}

/** 
* Return the seconds value from a mysql date/datetime
 */
function getSeconds(_mySqlDate) {
    if (empty(_mySqlDate)) return "";

    if (_mySqlDate.indexOf(":") >= 0) {
        var _els = _mySqlDate.(" ");

        if (empty(_els[1])) {
            _els[1] = _els[0];
        }

        _arrTimes = _els[1].split(":");
        return _arrTimes[2];
    } else {
        return "";
    }
}

/** 
* Return the date with into version dd/mm/yyyy or dd/mm/yyyy hh:mm:ss 
*/
function getDateTime(_mySqlDate, _printTime, _noMilliseconds) {

    if(_printTime !== false) _printTime = true;
    if(_noMilliseconds !== true) _noMilliseconds = false;

    var _date = getDay(_mySqlDate)+"/"+getMonth(_mySqlDate)+"/"+getYear(_mySqlDate);

    if (_mySqlDate.indexOf(":") >= 0) {

        var _els = _mySqlDate.split(" ");
        if (getDay(_mySqlDate) == "") {
            return false;
        }

        if (_els[1] == "00:00:00") {
            _els[1] = "";
        }

        if (_printTime) {
            if (_noMilliseconds) {
                _times = _els[1].split(":");
                _date += " " + _times[0] + ":" + _times[1];
            } else {
                _date += " " + _els[1];
            }
        }

        return (_date == "00/00/0000") ? "" : _date;
    } else {

        if (getDay(_mySqlDate) == "") {
            return false;
        }

        return (_date == "00/00/0000") ? "" : _date;
    }
}
Categories: JavaScript

Empty function from php to javascript


One of the most used function of php is the empty() function.
Unfortunately it’s not present in javascript and here there is the derived code.
I hope it will help you:

 

function empty (mixed_var) {
    if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || 
        mixed_var === null || mixed_var === false || 
        typeof mixed_var === 'undefined') {
        return true;
    }

    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }

    return false;
}

 

Categories: JavaScript
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: