Backup MYSQL database using PHP

Backup database using PHP

Sometime we need to backup MYSQL database without access to PHPMYAdmin in scenarios when need to do this through a scheduled job. Here is a code snippet I found to backup database using PHP.

This will also allow to backup complete database or single table.

{code}
backup_tables(‘localhost’,’DB_USER_NAME’,’DB_PASSWORD’,’DB_Name’);

/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = ‘*’)
{

$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);

//get all of the tables
if($tables == ‘*’)
{
$tables = array();
$result = mysql_query(‘SHOW TABLES’);
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(‘,’,$tables);
}

//cycle through
foreach($tables as $table)
{
$result = mysql_query(‘SELECT * FROM ‘.$table);
$num_fields = mysql_num_fields($result);

$return.= ‘DROP TABLE ‘.$table.’;’;
$row2 = mysql_fetch_row(mysql_query(‘SHOW CREATE TABLE ‘.$table));
$return.= “\n\n”.$row2[1].”;\n\n”;

for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); fwrite($handle,$return); fclose($handle); } {/code}

How to show post from Blogger on your website

Show Blogger content on Your Website

I was recently working on a website in Open source and blog of that site was being managed on Blogger.com, in general case when blog is self hosted on same domain or is in WordPress is become quite easy to show the post on the website. Here also the same requirement was faced where I had to show the blog post on website but from blogger.com

Initially is sounded something quite complex due to my limited exposure with blogger but once I checked the post structure it become quite easy to achieve this. I did this using MagpieRSS, a free to use open source project for converting various types of RSS feed. I support Blogger too. Step by step process to achieve this is as below:

Step 1: Download Magpie RSS

Step 2: Extract downloaded files in a directory named magpierss in ROOT of your project.

Step 3: Open PHP page where we need to display list of post from blogger and paste below code, I assume you :
{code}

{/code}
Now we have to display post data fetched from blogger:

a. If you want to display POST TITLE along with DESCRIPTION from blogger on your website, use below code:
{code}
items[0];
$content = $item[‘atom_content’];
echo “

Latest Blog Entry:
$content

\n”;
?>
{/code}
b. If you want to display POST TITLE ONLY from blogger on your website, use below code:
{code}
Latest blog additions:\n”;

foreach ($rss->items as $item) {
$href = $item[‘link’];
$title = $item[‘title’];
$created = $item[‘created’];

echo “

  • $title $created
  • \n”;
    }
    echo “

    “;
    ?>
    {/code}
    c. b. If you want to display ‘N’ number of POST TITLE from blogger on your website, a small change in above code is required and it will be as below:
    {code}
    Latest blog additions

      “;
      define(‘MAGPIE_DIR’, ‘magpierss/’);
      require_once(MAGPIE_DIR.’rss_fetch.inc’);

      $num_items = 7; // Number of post we wish to display
      $rss = fetch_rss( ‘http://yourblogname.blogspot.com/atom.xml’ );
      $items = array_slice($rss->items, 0, $num_items);

      foreach ($items as $item) {
      $href = $item[‘link’];
      $title = $item[‘title’];
      echo “

    • $title
    • \n”;
      }
      echo “

    “;
    ?>
    {/code}

    JQuery and WordPress

    JQuery and WordPress

    If you are trying to add your own jQuery code to WordPress, and have had the error “$ is not a function” show up on Firebug, here is the fix:

    Convert all dollar signs ($) to ‘jQuery’
    The dollar sign is reserved in WordPress for the Prototype library, which is why it errors out. For example, instead of:

    $().ready(function() {
    $(“#select_me”).show();
    });

    Change it to:

    jQuery().ready(function() {
    jQuery(“#select_me”).show();
    });

    MX record settings for using Google apps

    Since I starting using Google app, I feel traditional webmail not much efficient in terms of usage. Yes I do admit I have become a huge fan of Google apps and for same reason I have suggested and implemented it for most of my clients.

    There are several reasons to use Google apps to enhance you business:
    – No more need to worry about Microsoft Outlook, office license etc.
    – No need of any additional backups of server as you can surely rely on Google for that
    – Seamless integration of users for an organization/business
    – Overall it very easy to use because of it interface, which most internet users are already aware of being a Gmail user

    The only thing I mostly need to search every time I configure is MX records for using Google apps, to make it more handy and easy accessible (also for your help, if required) I thought to add it on blog and avoid searching each time:

    We need to update MX records as below:
    Priority Mail Server
    1 ASPMX.L.GOOGLE.COM.
    5 ALT1.ASPMX.L.GOOGLE.COM.
    5 ALT2.ASPMX.L.GOOGLE.COM.
    10 ASPMX2.GOOGLEMAIL.COM.
    10 ASPMX3.GOOGLEMAIL.COM.

    Dont forget to select ‘Remote Mail Exchanger’ to avoid routing issues

    Commands for Command prompt

    With every new version of windows interface is enhanced and it becomes more easy for user to use the system but still hardcore programmers wish to use the command prompt to for programs and other feature. Command prompt is an extensive useful utility for programmers and advanced users. It is a non-graphical interface that allows you to interact with your operating system. At the command prompt, you enter commands by typing their names followed by options and arguments. Remember the last time you wish to restart IIS and forgot the command : ) No issue, here is a list of most frequent user commands for command prompt for advanced users:
    Accessibility Controls = access.cpl
    Accessibility Wizard = accwiz
    Add Hardware Wizard = hdwwiz.cpl
    Add/Remove Programs = appwiz.cpl
    Administrative Tools = control admintools
    Adobe Acrobat ( if installed ) = acrobat
    Adobe Distiller ( if installed ) = acrodist
    Adobe ImageReady ( if installed ) = imageready
    Adobe Photoshop ( if installed ) = photoshop
    Automatic Updates = wuaucpl.cpl
    Basic Media Player = mplay32
    Bluetooth Transfer Wizard = fsquirt

    Calculator = calc
    Ccleaner ( if installed ) = ccleaner
    C: Drive = c:
    Certificate Manager = cdrtmgr.msc
    Character Map = charmap
    Check Disk Utility = chkdsk
    Clipboard Viewer = clipbrd
    Command Prompt = cmd
    Command Prompt = command
    Component Services = dcomcnfg
    Computer Management = compmgmt.msc
    Compare Files = comp
    Control Panel = control
    Create a shared folder Wizard = shrpubw

    Date and Time Properties = timedate.cpl
    DDE Shares = ddeshare
    Device Manager = devmgmt.msc
    Direct X Control Panel ( if installed ) = directx.cpl
    Direct X Troubleshooter = dxdiag
    Disk Cleanup Utility = cleanmgr
    Disk Defragment = dfrg.msc
    Disk Partition Manager = diskmgmt.msc
    Display Properties = control desktop
    Display Properties = desk.cpl
    Display Properties (w/Appearance Tab Preselected ) = control color
    Dr. Watson System Troubleshooting Utility = drwtsn32
    Driver Verifier Utility = verifier

    Ethereal ( if installed ) = ethereal
    Event Viewer = eventvwr.msc
    Files and Settings Transfer Tool = migwiz
    File Signature Verification Tool = sigverif
    Findfast = findfast.cpl
    Firefox = firefox
    Folders Properties = control folders
    Fonts = fonts
    Fonts Folder = fonts
    Free Cell Card Game = freecell

    Game Controllers = joy.cpl
    Group Policy Editor ( xp pro ) = gpedit.msc
    Hearts Card Game = mshearts
    Help and Support = helpctr
    Hyperterminal = hypertrm
    Hotline Client = hotlineclient

    Iexpress Wizard = iexpress
    Indexing Service = ciadv.msc
    Internet Connection Wizard = icwonn1
    Internet Properties = inetcpl.cpl
    Internet Setup Wizard = inetwiz
    IP Configuration (Display Connection Configuration) = ipconfig /all
    IP Configuration (Display DNS Cache Contents) = ipconfig /displaydns
    IP Configuration (Delete DNS Cache Contents) = ipconfig /flushdns
    IP Configuration (Release All Connections) = ipconfig /release
    IP Configuration (Renew All Connections) = ipconfig /renew
    IP Configuration (Refreshes DHCP & Re-Registers DNS) = ipconfig /registerdns
    IP Configuration (Display DHCP Class ID) = ipconfig /showclassid
    IP Configuration (Modifies DHCP Class ID) = ipconfig /setclassid

    Java Control Panel ( if installed ) = jpicpl32.cpl
    Java Control Panel ( if installed ) = javaws
    Keyboard Properties = control keyboard

    Local Security Settings = secpol.msc
    Local Users and Groups = lusrmgr.msc
    Logs You Out of Windows = logoff

    Malicious Software Removal Tool = mrt
    Microsoft Access ( if installed ) = access.cpl
    Microsoft Chat = winchat
    Microsoft Excel ( if installed ) = excel
    Microsoft Diskpart = diskpart
    Microsoft Frontpage ( if installed ) = frontpg
    Microsoft Movie Maker = moviemk
    Microsoft Management Console = mmc
    Microsoft Narrator = narrator
    Microsoft Paint = mspaint
    Microsoft Powerpoint = powerpnt
    Microsoft Word ( if installed ) = winword
    Microsoft Syncronization Tool = mobsync
    Minesweeper Game = winmine
    Mouse Properties = control mouse
    Mouse Properties = main.cpl
    MS-Dos Editor = edit
    MS-Dos FTP = ftp

    Nero ( if installed ) = nero
    Netmeeting = conf
    Network Connections = control netconnections
    Network Connections = ncpa.cpl
    Network Setup Wizard = netsetup.cpl
    Notepad = notepad
    Nview Desktop Manager ( if installed ) = nvtuicpl.cpl

    Object Packager = packager
    ODBC Data Source Administrator = odbccp32
    ODBC Data Source Administrator = odbccp32.cpl
    On Screen Keyboard = osk
    Opens AC3 Filter ( if installed ) = ac3filter.cpl
    Outlook Express = msimn

    Paint = pbrush
    Password Properties = password.cpl
    Performance Monitor = perfmon.msc
    Performance Monitor = perfmon
    Phone and Modem Options = telephon.cpl
    Phone Dialer = dialer
    Pinball Game = pinball
    Power Configuration = powercfg.cpl
    Printers and Faxes = control printers
    Printers Folder = printers
    Private Characters Editor = eudcedit

    Quicktime ( if installed ) = quicktime.cpl
    Quicktime Player ( if installed ) = quicktimeplayer

    Real Player ( if installed ) = realplay
    Regional Settings = intl.cpl
    Registry Editor = regedit
    Registry Editor = regedit32
    Remote Access Phonebook = rasphone
    Remote Desktop = mstsc
    Removable Storage = ntmsmgr.msc
    Removable Storage Operator Requests = ntmsoprq.msc
    Resultant Set of Policy ( xp pro ) = rsop.msc

    Scanners and Cameras = sticpl.cpl
    Scheduled Tasks = control schedtasks
    Security Center = wscui.cpl
    Services = services.msc
    Shared Folders = fsmgmt.msc
    Sharing Session = rtcshare
    Shuts Down Windows = shutdown
    Sounds Recorder = sndrec32
    Sounds and Audio = mmsys.cpl
    Spider Solitare Card Game = spider
    SQL Client Configuration = clicongf
    System Configuration Editor = sysedit
    System Configuration Utility = msconfig
    System File Checker Utility ( Scan Immediately ) = sfc /scannow
    System File Checker Utility ( Scan Once At Next Boot ) = sfc /scanonce
    System File Checker Utility ( Scan On Every Boot ) = sfc /scanboot
    System File Checker Utility ( Return to Default Settings) = sfc /revert
    System File Checker Utility ( Purge File Cache ) = sfc /purgecache
    System File Checker Utility ( Set Cache Size to Size x ) = sfc /cachesize=x
    System Information = msinfo32
    System Properties = sysdm.cpl

    Task Manager = taskmgr
    TCP Tester = tcptest
    Telnet Client = telnet
    Tweak UI ( if installed ) = tweakui
    User Account Management = nusrmgr.cpl
    Utility Manager = utilman

    Volume Serial Number for C: = label
    Volume Control = sndvol32
    Windows Address Book = wab
    Windows Address Book Import Utility = wabmig
    Windows Backup Utility ( if installed ) = ntbackup
    Windows Explorer = explorer
    Windows Firewall = firewall.cpl
    Windows Installer Details = msiexec
    Windows Magnifier = magnify

    Windows Management Infrastructure = wmimgmt.msc
    Windows Media Player = wmplayer
    Windows Messenger = msnsgs
    Windows Picture Import Wizard (Need camera connected) = wiaacmgr
    Windows System Security Tool = syskey
    Windows Script host settings = wscript
    Widnows Update Launches = wupdmgr
    Windows Version ( shows your windows version ) = winver
    Windows XP Tour Wizard = tourstart
    Wordpad = write
    Zoom Utility = igfxzoom

    Currency converter using API

    Currency conversion and language conversion are two most frequent required features for a web developer. There are multiple options too available for both such as Google language widget etc. to acheive feature quickly in couple of mins with no code but some where they limit functionality due to dependency on 3rd party code. Personally I prefer use of API as much possible for integration of any functionality in compare to being dependent on any 3rd party provider and hamper own website’s design and programming creativity.

    In one of such scenario I recently come across Currency converted using Google API by TechMug, this really impressed me a lot. My requirement was to allow users to check the price (default in USD) and this solution worked like a charm. Demo of same can be viewed here.


    It make an ajax call to Google API using JQuery and pass the ‘To’ & ‘From’ currency and amount as argument. In response API return the value of currency in real time.

    Download Mirror

    CTRL + ALT + DEL in remote desktop

    It was always an issue for me as having multiple CPU but single monitor and I hate most when I have to access a System remotely because there is no option for CTRL + ALT + DEL, one of any computer users most favorite key combination. : )

    Finally I found it, here is a solution to access CTRL + ALT + DEL over remote desktop, just need to replace DEL with END. So combination while using remote desktop is CTRL + ALT + END

    Cheers!!

    Share on Facebook with Description

    Recently one of my collegue was struglling with sharing information on Facebook using Sharer.php, earlier it was a good and easiest way to share or post on Facebook progrmatically. It used to take 2 arguments u & t:

    http://www.facebook.com/sharer.php?u=http://yahoo.com&t=description_here
    The u argument is the url that you are sharing.
    The t argument should be the descriptive text that goes along with the post. However this is deprecated and no longer works.

    Now if this is used it post, page title as description which is not desirable in most of cases.

    I googled as well checked Open Graph meta tag (https://developers.facebook.com/docs/opengraph/), which same I also reviewed an article by Petisia showing same using meta tags but we need a separate PHP code file in this.

    Finally after bit of study I was able to come up with an option which allow to post URL, description, image etc. to wall using single share file link:

    http://www.facebook.com/sharer.php?s=100&p[title]=YOUR TITLE HERE;p[url]=YOUR URL HERE&p[images][0]=IMAGE PATH HERE&p[summary]=YOUR DESCRIPTION HERE”>

    Click to view live demo

    Above link will allow you to post a link with details on Facebook to this blog post

    XML based slideshow in Flash

    Recently I was going though some old open source code in archive and found few code snippets of JQuery, Flash application, PHP, wordpress helpful in web development. I have added a flash based slideshow managed using XML here. It uses a simple XML file to manage flash and different images can be managed category wise with no much efforts. It is quite suitable for a portfolio display.

    Click to Download

    I am unable to recall original source of download but still appreciate efforts of Flash developer who invested efforts in this nice Flash based slideshow.