Recent Posts


Quick Script to Generate DB Dump


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This is a small PHP shell script that will extract the default connection information from local.xml and construct the correct command-line script to do a no-locking dump of the database. You’ll need to be in the root folder of a system for this to work.

Useful if you spend a lot of time debugging different systems.

#!/usr/bin/env php
    $xml = simplexml_load_file('app/etc/local.xml');
    $connection = $xml->global->resources->default_setup->connection;
    $username = $connection->username;
    $password = $connection->password;
    $db_name  = $connection->dbname;
    $host     = $connection->host;

    $cmd = 'mysqldump '     .
    '-u ' . $username . ' ' .
    '-p'  . $password . ' ' .
    '-h ' . $host     . ' ' .
    '--lock-tables=false '  .  
    '--single-transaction ' .
    $db_name . ' > '        .

    echo $cmd . "n";

Copyright © Alan Storm 1975 – 2022 All Rights Reserved

Originally Posted: 14th March 2012