Tuesday, March 30, 2010

Export and import database to and from remote servers through telnet

Hi, If you want to take database backup from one server and import it into another remote server use the below process.


Import command at terminal or dos
mysql -u user_login -p database_name < /path_to_the_file/my_backup.sql

Export command at terminal or dos
mysqldump -u user_login -p database_name > /path_to_the_file/my_backup.sql

Database Backup
connect to remote host with SSH from termail using below command
#ssh user@host.com
password:
After login, crate one folder to store the backup file and make it writeble, then run the beloc ommand to take backup for the whole database
#mysqldump -u dbusername -p dbname > dbbackup.sql
It will ask you the dbpassword

After download ddbackup.sql and transfer to new host where you have to set up the database..

connect to remote host with SSH
#mysql -u dbusername -p dbname -e 'source dbbackup.sql'
It wil ask you the dbpassword.


The other way, which is even cooler, and more secure, assuming you have ssh access on both machines (this, again, is a direct dump-to-import):

mysqldump -ux -px database | ssh me@newhost "mysql -ux -px database"

This will dump the data to stdout, pipe it to ssh @ the newhost, and into mysql. Of course, replace all x's with username's and password.


If you want to keep two databases equal, you can use rsync (if your system supports it) to do it by creating a simple script:

rsync you@yourserver::share/path/to/mysql/data/* /path/on/the/other/server/

that you call with a cron job every 10 minutes/1 hour/1day/...

This way, whenever your database change, rsync will find the difference and would transfer ONLY the bytes that have changed.

Ref: http://www.webhostingtalk.com/archive/index.php/t-226992.html

Saturday, March 27, 2010

Drupal Image gallery creation

http://jamestombs.co.uk/2009-05-12/create-an-album-based-image-gallery-in-drupal-6-using-cck-and-views/1045

http://www.primalmedia.com/blog/building-better-drupal-photo-gallery

Background color problem for fckeditor in Drupal

When you install fckeditor module in drupal you might get problem that editor's background color is applied from body background color. To fix this background color problem add another line in fckeditor.config.js:
FCKConfig.EditorAreaStyles = "body{background:#FFFFFF;text-align:left;}";

Other tips for fckeditor in drupal http://drupal.fckeditor.net/tricks

Friday, March 26, 2010

Get IP address of the site visitor in rails application

In RAILS_ROOT/app/controllers/show_my_ip_controller.rb

class ShowMyIpController < ApplicationController
def index
@client_ip = request.remote_ip
end
end


In RAILS_ROOT/app/views/show_my_ip/index.html.erb

Your IP address is <%= @client_ip %>

Tuesday, March 23, 2010

Commands to start apache server and mysql server in linux

To start Apache webserver in linux (LAMP)

#service httpd start
the above command will start both apache and mysql servers.

To start Mysql server in linux (LAMP)
#service mysqld start

Thursday, March 18, 2010

Working with Float values

While you are working with float numbers and you should always want to display 1 or 2 numbers only after precission ex: You like to display 5.30 instead of 5.29088388434. To display in that format we have to use below functions

In Ruby:

f=1.23456
puts sprintf('%.2f', f).sub(/0{1,2}$/, '')

In php:
$$grandtotal = $rate*$miles;
echo number_format($grandtotal,2);
?>

Monday, March 15, 2010

Multiple layouts for each Wordpress Page

The solution:
Edit ‘page.php’ to check what page your on, and then load the appropriate template.

The implementation:
If you edit page.php you’ll notice that it calls the get_header() and get_footer() functions. This is about the only bit of code that we want to keep in this file.

First Step:
First, make a copy of page.php and give it a name. This is your first template. Delete the header and footer calls from your template, because we’re going to load this into page.php, and it will have already called them.

Second Step:
Open page.php and delete everything between the header and footer calls. In this space, add a PHP conditional that uses the is_page() function.

if(is_page(107) == true) {
include ‘page_full.php’;
} else {
include ‘page_twocolumn.php’;
}

?>

Here’s an example of what I did to load multiple page layouts:

if(is_page(107) == true) {
include ‘page_films.php’;
} else if(is_page(array(518, 28, 13)) == true) {
include ‘page_full.php’;
} else {
include ‘page_twocolumn.php’;
}

?>

This sets page with ID 107 to use the template specific for the ‘films’ page. It also sets pages with ID’s 518, 28, and 13 to use the full page layout. All others use the two column layout.

That’s it!

Default timezone settings in PHP

date_default_timezone_set('Asia/Calcutta');