Posted in: mysql | ( 2 ) Comments
4 Oct 2011I recently had to update a MySQL schema and import new data into the table. But before I could do that I needed to check that no one had updated the table during the last 7 days and no new data had been stored. As the table itself did not have any update field of itself the only other option was to look into the MySQL ‘information_schema’ database.
The ‘information_schema’ database contains a ‘tables’ table which contain the update information for each database and its tables. So all you have to do is grab that information.
Posted in: mysql,php | ( 5 ) Comments
2 Oct 2011One of the frustrating things with working with MySQL is of importing large sql dump files. Either you get a ‘max execution time exceeded’ error from PHP or a ‘Max_allowed_packet_size’ from MySQL. In a recent task I needed to import a table of around a million records on a remote host, which quickly became an exercise in frustration due to various limitations on the server. SSH was of no help as changing the configuration files was restricted to the root user.
My last resort was to split the huge ‘INSERT’ statements into smaller size files. Manually doing the same is obviously time consuming and error prone; the only other solution is to write a small script to split the insert statements. This was to be a quick hack so the parsing code was to be of minimum complexity. Splitting a sql dump containing extended insert statements is somewhat complex so you need to have the dump file in a simple format – each insert statement should be on its own line as shown below.
A recent task needed me to import a large amount of data from a Access MDB database to MySQL. My first choice for the job was the mdb-tools set of utilities. mdb-tools provides a set of tools and applications to export MDB data and schema to other databases such as MySQL, Oracle, Sybase, PostgreSQL, and others.
mdb-tools is available for Linux systems, and as I use Ubuntu, installation was a breeze using the package manager. To install is from the shell use the following.
Posted in: mysql,php | ( 2 ) Comments
14 Sep 2011Creating a database driven web application involves commonly used paradigms for data modification, which we commonly refer to as CRUD. Frameworks provides nice ORM wrappers to help the programmer. But for small projects frameworks can be an overkill. Still the programmer needs to design the basic database CRUD functionality, which can be quite tedious and repetitive. This is where auto database class generators can be helpful. If you have your database schema ready, you can automatically create the respective class wrappers for the tables.
Posted in: wordpress | Comments Off
13 Sep 2011I’ve recently updated the country filter plugin to use the MaxMind database along with the ip2nations database. Country Filter plugin allows you to control the visibility of WordPress elements depending on the users country of origin. You can hide or show certain elements of a page or some sections of a post from users browsing from a particular country.
For example you could have a ‘donate’ button on a sidebar that displays only if the user is browsing from France. Or you could hide a particular paragraph in a post for users from a particular country. This can be used by marketing people to deliver targeted content to audiences.
Developers and designers could also use the plugin to load different stylesheets based on the users country. Services like hulu.com uses techniques such as this to constrain viewership to a particular country.
You can buy the plugin from here.
Underscore.php is a PHP port of the popular Underscore.js library. Underscore.php provides a utility library for PHP that provides a lot of the functional programming support that a programmer would expect in Ruby, but without adding much overhead during execution. The only caveat is that underscore.php requires PHP 5.3 or greater. Although you could accomplish some of the things using PHP’s built in functions, the functional style approach looks intuitive and easy to work with. Note that this not a purely functional programming like Haskell. It would be nice to integrate the library in your CakePHP framework, which will help bring some functional flavor to the framework.
Take a quick example of the ‘pluck’ method.
include_once('underscore.php'); $members= array( array('name'=>'bill', 'age'=>40, 'gender' => 'm'), array('name'=>'john', 'age'=>50, 'gender' => 'm'), array('name'=>'sarah','age'=>60, 'gender' => 'f') ); $ret = __::pluck($members, 'name'); print_r($ret); |
Posted in: php | ( 8 ) Comments
4 Sep 2011Microsoft Language translation is an interesting service. Not only can you do language translation, you can also detect the language of a particular text. The given class provides a PHP wrapper which will help developers translate text from one language to another in a easy manner. The library also supports caching, helping you keep your translations fast and simple.
One of the important reasons for the popularity of WordPress is its plugin architecture, which has enabled thousands of programmers to write additional functionality for WordPress. But the plugins are constrained in silos, unable to be controlled by outside programs ( well this can be advantageous if you consider security).
Take the popular WP-Super-Cache plugin. I frequently make changes to my blog from a FTP client, and every time I’ve to login to the WordPress admin and clear the cache so that I can see the latest changes reflected. At times this can be tiring. It would be nice if one could have a desktop app that interfaces with the remote WP-Super-Cache instance. This is exactly what we will do in the current post.