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

Verify EAN 13 in MySql

23 March 2012 3 comments

To verify the correct structure of an EAN13  with MySql we can create a function as the follow.

DROP FUNCTION IF EXISTS FNC_IS_VALID_EAN13;

DELIMITER $$
CREATE FUNCTION FNC_IS_VALID_EAN13(_ean VARCHAR(13)) RETURNS tinyint(4)
READS SQL DATA
BEGIN
DECLARE _correct_ean TINYINT;
DECLARE _even_sum SMALLINT;
DECLARE _odd_sum SMALLINT;
DECLARE _check_digit SMALLINT;
DECLARE _check_number SMALLINT;
IF LENGTH(_ean) 13 THEN RETURN 0; END IF;
IF NOT _ean REGEXP ‘^[0-9]+$’ THEN RETURN 0; END IF;
SELECT SUBSTR(_ean, 0, 1)+SUBSTR(_ean, 2, 1)+SUBSTR(_ean, 4, 1)+SUBSTR(_ean, 6, 1)+SUBSTR(_ean, 8, 1)+SUBSTR(_ean, 10, 1) INTO _even_sum;
SELECT SUBSTR(_ean, 1, 1)+SUBSTR(_ean, 3, 1)+SUBSTR(_ean, 5, 1)+SUBSTR(_ean, 7, 1)+SUBSTR(_ean, 9, 1)+SUBSTR(_ean, 11, 1) INTO _odd_sum;
SELECT ( (10-(3*_even_sum + _odd_sum)%10)%10 ) INTO _check_digit;
SELECT SUBSTR(_ean, 13, 1) INTO _check_number;
SELECT IF(_check_number=_check_digit,1,0) INTO _correct_ean;
RETURN _correct_ean;
END$$
DELIMITER ;

 

To use it simply just type into your queries something like this:

SELECT ean, FNC_IS_VALID_EAN13 (ean) as isValid FROM MY_TABLE;

That’s it

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: