Skip to main content

Posts

Showing posts from 2014

Recovering an InnoDB table from only an .ibd file

Sometime you may need to recover a table when all you have is the .ibd file. In this case, if you try to load it into a new instance, your likely to encounter some errors about the table id not matching. And there is not really a way around this. However, I’ve found two work-arounds for this: Note: You will need the .ibd file and the CREATE TABLE statement for each table you want to recover using these methods. Simulate the internal InnoDB table counter. That is, create work tables (with innodb_file_per_table enabled) until you have the internal pointer of table id equal to (1 – id_of_ibd_table_you_need_to_restore). (See Method #1) Manually hex edit the .ibd file, changing the table id. (See Method #2) *Note: There are some internal structures with this meta information, so you’ll need to dump/import that data after you get it loaded, so you avoid unpleasantries that will inevitably show their face. Method #1 – Create work tables Start up clean/fresh instance of...

Convert Date Time to GMT/UTC

If you want to convert any date time to GMT/UTC for given timezone (observing DST/not). /**      * coverts the given date time to GMT/UTC based on timezone provided      * @param string $date      * @param string $timezone      * @return string      */     function getGMT($date, $timezone){         date_default_timezone_set("UTC");         $daylight_savings_offset_in_seconds = timezone_offset_get( timezone_open( $timezone ), new DateTime() );         return $new_date = date('Y-m-d H:i:s', strtotime('-'.$daylight_savings_offset_in_seconds.' seconds', strtotime($date)));     } $date = "2014-11-30 23:50:00"; //yyyy-mm-dd //$date = "11/30/2014 23:50:00"; //mm/dd/yyyy //$date = "30-11-2014 23:50:00"; //dd-mm-yyyy $timezone = "Asia/Kolkata"; //$timezon...

Find Random Coordinates in the proximity

If you are asked to find the random coordinates (latitude & longitude) considering that your latitude & longitude as the center and with in the given proximity (radius), then this service will help to get one such coordinate. An example, you are at X location (17.414472, 78.449024) and radius 1 mile.  /**      * picks the random latitude & longitude with respect to given within the provided radius      *      * @param array $centre    (lat, lng)      * @param number $radius                 * @return array:      */     function getCoordinates($centre, $radius)     {         $radius_earth = 3959; // miles                   ...