How To Create A Patch For Updated Script

Recently I had to make few changes on a freely distributed CGI script. We do these changes to fix bugs or add useful features.

We use patch files to share those changes with other developers and those patches are useful to re-apply them to new versions of the script.

The package we use for this is ‘diff’. You can learn more about it from ‘man diff’ and play with it.

This is the command I use to generate patch files:

diff -crB original_file updated_file > file.patch

 

How to get a mysqldump by selecting data

Its just simple as follows,

mysqldump -p<password> <user> <database> –where=”<where condition>” > <mysqldump file name>.sql

 

example :

mysqldump -ppassword root test_db –where=”name LIKE ‘A%’ age between ’20’ and ’30’ ” > a20to30.sql

 

Important thing should do when we delete large number of records from a MySQL table

When you deleting large number of records from a MySQL table, remember to execute following command after deleting the records.

OPTIMIZE TABLE tablename;

By executing this command we can improve performance of the table queries and save storage space.

You can find detail explanation from : http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

Date/Time addition in PHP

Using PHP ‘strtotime()’ function, we can add time in our PHP programs.
Example:

$date = strtotime(“+10 minute”, strtotime(“2007-02-28 23:55:05”));
echo date(“Y-m-d H:i:s”, $date);     //gives 2007-03-01 00:05:05

Try following:

$date = strtotime(“+3 day”, strtotime(“2007-02-28 23:55:05”));
echo date(“Y-m-d H:i:s”, $date);

Send emails using PHP

In PHP there is a function called “mail” for send emails from our web applications. To use this this function, we have to do some configurations in php.ini file of our web server. If you are using PHP-equipped web host, you don’t need to worry about this mail function setup configuration because all required configurations are done by the hosting providers.

 

Setting up mail function in PHP

=====================

step 1> Goto “php.ini” file in your web server.

step 2> Find “[mail function]” part in the php.ini file.

step 3 for window mail server> Give the mail servers address to “SMTP”, give the port of the SMTP to “smtp_port” (default is 25) and set “sendmail_from” to sender’s email address.

eg:

[mail function]

SMTP = smtp.my.isp.net

smtp_port = 25

sendmail_from = you@yourdomain

step 3 for unix mail server> Give the path of the mail program on your server and set “sendmail_from” to sender’s email address.

eg:

[mail function]

sendmail_path = /usr/sbin/sendmail -t

sendmail_from = you@yourdomain

 

PHP mail function sample code

======================

<?php

// The message

$message = “Line 1\nLine 2\nLine 3”;

// In case any of our lines are larger than 70 characters, we should use wordwrap()

$message = wordwrap($message, 70);

// Send

mail(‘first_user@example.com,second_user@example.com‘, ‘The Subject’, $message);

?>

refer :http://php.net/manual/en/function.mail.php

MySQL 5.1 New Features: MySQL Partitions

I had a problem with handling huge amount of data in one of my MySQL databases. Problem is its take too much time to generate reports from a huge data collection.
I found many ways to solve this problem and also this new MySQL table Partitioning feature. Its come with MySQL 5.1.

Using this feature we can increased performance of MySQL data scan operations as I needed above. And also simplified data management.

Read following for more:
http://dev.mysql.com/tech-resources/articles/performance-partitioning.html

Database Normalization (1 to 3rd form)

In the relational database design, normalization is a systematic way of ensuring that a database structure is suitable for querying without insertion, update, and deletion anomalies that could lead to a loss of data integrity.

1st Normal Form
============
First you have to know what are the multivalued and composite attributes to understand the 1st normal form.

Multivalued Attribute is a attribute which can have more then a single value. For an example we can take a  person’s telephone number. We can take many numbers as telephone number (Home tel number,Mobile number, tel number at office). To remove a multivalued attribute we have to divide the attribute.
Example: If we have attribute called “telephone”, then we can divide it as “home telephone”, “mobile number”, “office number”.

Composite attribute is a attribute which have several attributes. For an example the address attribute is can take as composite attribute. To remove this attribute we can divide the attribute to the sub attributes.
Example: If we have attribute called “address”, then we can divide it to “no.”, “street1”, “street2”, “city”, “country”.

These kind of attributes (multivalued and composite) should removed from the relation schema to get first normal form relation.

2nd Normal Form
=============
In the 2nd normal form it consider two dependencies called Functional dependencies and Partial dependencies. And also you should have the knowledge of primary key of a relational schema.

Functional dependency occurs when one attribute in a relation uniquely determines another attribute.

Partial dependency occurs when non-key attribute in a relation uniquely determines by sub set of primary key attribute set. Therefore to occur these kind of dependencies the primary key should contain more than one attributes.

All attributes in a relational schema should be fully functionally depend on the primary key of that relational schema. It means there should not occur any partial dependencies.

3rd Normal Form
=============
relational schema which have no transitive dependencies, called 3rd normal formed relational schema. transitive dependency occurs when a non-key attribute in a relational schema depends on another non-key attribute.

%d bloggers like this: